Download

Attach ActorComponent to Actor?

I’ve been looking around, seeing the source code of the templates and googling my issue, but I can’t figure out how to do an important and simple operation. I just created an ActorComponent, and added the dependncy to my ACharacter class (ThirdPerson C++ Template Character Class), after looking at the components added, they use a simple “SetupComponent->(RootComponent)” structure which apparently my actor component doesnt posses. I tried creating a DefaultSubObject and just adding it as a member but it doesn’t seem to be attached. Here is my code without any attachment logic…

Character.h
…]
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Combat)
UCameraLockOnComponent* LockOnComponent;
…]

Character
…]
LockOnComponent = CreateDefaultSubobject<UCameraLockOnComponent>(TEXT(“LockOnComponent”));
…]

How do I properly set this component up so that the character class can call functions in my component?

Hi,

If you do the CreateDefaultSubobject in the constructor it should be fine. Just use LockOnComponent-> to call functions from that actor component. Make sure they are not private.

Best
Dominic

Thanks very much!

So, There is a bit of difference between Actor Components and Scene Components.
Scene Components are the ones that have access to transforms good example of this is Static Mesh Component you can attach that to an Actor.

And Others are Actor Components if you look at UE4 hierarchy you will see Actor Component is the parent of Scene Component. These don’t have access to AttachToActor or AttachToComponent functionality. The best example I can think of these is look at Character Movement Component In the Character Class.