I hava a hard question ,I don’t understand the UClass and it’s drived classes use for?
When I see official documentation,it has said when a class drived form UObject,a UClass object will be created for the class. But I don’t understand what dose this mean. I hope someone can offer me a more clear explaination. Thanks !
UClass is part of reflection system and it’s class identification which can be use to point for specific class (in varable for example or used as function argument like SpawnActor to spawn actor of specific class) which normally it’s not possible in C++, you can only use class name in few operators like “new” or “sizeof”. Properties, Structs, Functions has such identification classes all derived from UField:
They used to map all functions propeties and stuff, not only for editor but it can be also used in game.
As reflection system, only accepts classes drived from UObject, so only UObject can have representetive UClass, if you gonna create non reflected class (without UCLASS()) it won’t have representative UClass and won’t be seen by engine… but they will work, just they might not work with some engine features.
UClass it’s easiest to get as every as all UObjects have static function called “StaticClass()” which returns UClass of class that they been called from, so if you want spawn AApple actor for example you don’t need instance of it to get UClass (and you can do so using GetClass() function which you should use if you want to get class of object instance), you just do ()->SpawnActor(AApple::StaticClass());
and it will spawn AApple Other identifiers from diffrent kind of UFields are little harder to get then that