I am new to Cpp and I was trying to think why UPhysicsHandleComponent was set as a pointer? And how would I know in general when should i initialize a component/or parameter as pointer? (Sorry if its a silly question). The unreal doc for this doesnt mention anything as such.
- Everything derived from UObject needs to be dynamically allocated during runtime so they would always be pointers. Here’s an article on dynamic memory
https://www.learncpp.com/cpp-tutorial/dynamic-memory-allocation-with-new-and-delete/
(You should not be doing this yourself in Unreal). - The instance of the physics handle is already created in BP you just want to point to that same instance. Without it being a pointer you would be storing a copy (also it wouldn’t compile due to 1, you can’t create UObjects on the stack).
3 Likes
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.