Add component to actor in C++ (the final word!)

It depends on component type :wink:

. If your component doesn’t need to “talk” to the
engine (rendering/collision/navigation/replication) then you don’t even need to register it.

Simply put, if a component inherits from USceneComponent then a call to RegisterComponent () is required.

If you want the actor’s transformation to affect the component as well, you need to use AttachTo* function. (implicitly requires registration)

InstanceComponent…
From what I understand, InstanceComponent is just a convention, some standardization of access to “optional” components. Actor does not have to own such a component.

In Actor constructor you can only use CreateDefaultSubobject. This creates a kind of “shape” of a Actor. Adds given component to related UClass, so any instance of this Actor have its ‘by default’. Unlike instanced components, which may only contain certain instances of a given actor.

2 Likes