Help Understanding TSubclassOf<> When Spawning
Maybe I'm just not understanding this right, but what is the point of using TSubclassOf ? It seems kind of general... What if I wanted to spawn a specific child class of pickup. I.e. if I have a parent class called pickup and I have derived classes that give health, one that gives mana, etc. How would I go about delineating which specific subclass I am referencing? For example, if I made a health potion spawning class had a property in the header that looked like:
and then in the .cpp it might have some function like SpawnHealthPotion():
It just seems sort of pointless because it seems like I have nowhere specified that I want a health potion to be spawned as opposed to, say, the mana potion, both of which are subclasses of APickup. Maybe I'm just not understanding this right, or there's a better way to go about doing this when there are multiple child classes of a parent.
asked May 19 '16 at 03:09 PM in C++ Programming
TSubclassOf in reality is UClass*, only diffrence is that TSubclassOf limit selection of classes in editor to specific class relation (and i think it also limits that in C++ too but i never deared to try it, i personally only use it limit selection in editor), other then that it is still fully functional UClass*. UClass object is class identifier in UE4 reflection system, each C++ and Blueprint class has one, by it you can check if class you talking to is a class you expect to be or you can reffer to specific class (which you do in SpawnActor), which normally impossible in C++, thats what reflection system is for and not only that.
Here is what you can do with UClass: https://docs.unrealengine.com/latest/INT/API/Runtime/CoreUObject/UObject/UClass/index.html
Why not try setting the TSubClassof directly to child classes instead of Pickup class?
answered May 19 '16 at 03:18 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here