How can I instantiate a class derived from UClass in C++?

Hi.

Hi have a class that extends directly from UClass and I want to use it as a member in a Actor. How I can Instantiate this clase in the init of the actor ?

I tried standard contructors but I assume I have a factory method for UClasses. I saw how to deal with components and actor creation, but how to do it with a UClass?

Thanks!

May ask why you needed to extend UClass?

Yes. I am trying to make stats classes with logic for Actors. For example EnemyStat, PlayerStat, so on , and I want them to be accesible and usable from BluePrints as possible. There are another approach?

I guess you don’t know what UClass is for :stuck_out_tongue: it’s a class identifier, containing information about class, you can get UClass of any object from static function called StaticClass(). Also because you can’t reefer classes in C++ it is also used to point specific class in variables and function arguments (like ()->SpawnActor(ASomeActor::StaticClass()) where you need to point actor class you what to spawn.

I think you misunderstood it with UObject which is most basic object in engine… but even so i think you should place things like stats in Character or PlayerController or even PlayerState

Oh yes… I meant UObject =P . I want to place stats in the character, not like variables, but like an object object container, following a Composite Pattern.

How Can I instantiate UObjects then?

ConstructObject(ASomeClass::StaticClass());

Works similar to SpawnActor :slight_smile:

Currently it is:

NewObject(ASomeClass::StaticClass());

Someone mark this as the correct answer please!