i just started learning c++ for Unreal
now i came up with this situation:
You have for example “MovementComponent” and you want place it as a component in your “Character”
then i saw two ways of doing it
-
Create protected variable MovementComponent then set it in the constructor of the character like:
MovementComponent= CreateDefaultSubobject(FName(“MovementComponent”));
So you use the method CreateDefaultSubobject -
Add on the MovementComponent.h file inside the UCLASS() this:
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
And then just go to your character and click add component and you will find the Component.
Now i wondered which one is better qua performance and features
One thing i know is with method 2 you also have is as a variable in your character blueprint
Edit:
And with one should i use??