What exactly is TSubClassOf?

The documentation of TSubClassOf isn’t much clear about what it is, and the instructor didn’t elaborate much on what it is,

TSubclassOf is a template class that provides UClass type safety. For instance, let’s imagine that you are creating a projectile class that allows the designer to specify the damage type. You could just create a UPROPERTY of type UClass and hope the designer always assigns a class derived from UDamageType or you could use the TSubclassOf template to enforce the choice. The sample code below illustrates the difference:

/** type of damage */
UPROPERTY(EditDefaultsOnly, Category=Damage)
UClass* DamageType;

Vs.

/** type of damage */
UPROPERTY(EditDefaultsOnly, Category=Damage)
TSubclassOf<UDamageType> DamageType;

In the second declaration, the template class tells the editor’s property windows to list only classes derived from UDamageType as choices for the property. In the first declaration any UClass can be chosen. Pls mark this as the solution.

2 Likes

Thanks man

Your most welcome :slightly_smiling_face: :slightly_smiling_face: :smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms