Download

UActorComponent: illegal use of this type as an expression

I’m attaching “skills” to the player as Actor Components.

I have a c++ class that derives from UActorComponent called BaseSkill
Then I have a class that derives from BaseSkill called SkillBuilder

I cannot attach these in the constructor, because they can change at runtime, therefore I want to use the NewObject function within the ACharacter class to create them as needed.

.h


USkillBuilder* BuildSkill;


.cpp


FName BuildName = "Builder Skill";
BuildSkill = NewObject<UActorComponent>(this, USkillBuilder, BuildName);


But I get the error:


C2275    'UBaseSkill': illegal use of this type as an expression

How do I use NewObject to spawn and attach an actor component then? This seems to match all the examples I’ve seen online.

Thanks in advance.

Never mind. Seems that changing it to this fixed it:


FString BuildName = "Builder Skill";
BuildSkill = NewObject<USkillBuilder>(this, USkillBuilder::StaticClass(), *BuildName);


What does the StaticClass() do?