Hi!..
I have made some courses of cpp, and got how pointer Works (that i guess), but i´m wondering if there is an special reason why in Unreal all their types must be declared as pointers…
//This is fine
UStaticMeshComponent * myMeshComponent;
//Is this fine ?, if not, why ?
UStaticMeshComponent myMeshComponent;
Thanks in advance.
1 Like
I think components should be pointers because of Inheritance, you can set in your UStaticMeshComponent another class derived from UStaticMeshComponent and all virtual methods will be working, but with static initialization like “UStaticMeshComponent myMeshComponent;” object allocates in parent class memory and Object-Oriented Paradigms not working here.
When not using pointers, the members will be initialized during the construction of the object. Problem is, Components need to be created by the engine via NewObject<>() and RegisterComponent() instead of using new T(). So yes, all members of subtype UObject need to be pointers.
So the way is to use pointers for Unreal types and standard variables for game logics (dependes needed). ?
Anything that is subclass of UObject you declare as a pointer. The engine will manage where the object is created in memory, you only hold a pointer to it.
Structs and basic variable types however are meant to be used as value, or references.