Why use TSubClassOf and not just the class itself?
I have read the documentation and I have seen some questions asked regarding TSubClassOf, but none explain what the point of it all is.
What extra does it bring?
I can write UDamageType* dmgType =
or TSubClassOf* dmgType = .
The only accepted types in BOTH cases are UDamageType or a sub class. What does the latter option provide that the former does not? The editor let me set the type properly when exposes to blueprints.
What am I missing?
asked Jul 31 '16 at 11:39 AM in C++ Programming
the first one is a blue pin object reference, which is not a class reference at all, its a reference to an object that is already created, or it is null. the second one is a purple pin Class reference, used to create new objects from, but in the details panel it would create a drop down menu that allows you to select any class.
the third one is TSubclassOf, which is like the second one, where it is a purple pin Class variable used to create new objects from, but the editor's details panel will list only classes derived from UDamageType as choices for the property, instead of listing every class in the engine as an available replacement for that pointer.
so the first one is an object pointer, and the last 2 are class pointers, and the final one is a specific type of class pointer than narrows down the list of available class choices.
class pointers are different from object pointers, because UClass pointers reference class assets available in the editor, while object pointers can only be valid at runtime, because they can only reference objects that are already created or spawned into ram during gameplay.
so if you were making a weapon pickup item, where you wanted the designer to be able to choose the damage type for that weapon from the details panel, you would use
then on begin play, you can use
that will give you a pointer to a created object of a type decided in the editor by a designer.
Follow this question
Once you sign in you will be able to subscribe for any updates here