Why TSubclassOf?

Hi,
I read the UE4 documentation and understand what a TSubclassof class is used for, however I am not sure why the lecture chose to use this in the ToonTanks course.
In the ProjectileBase actor, he declared a DamageType, however as follows:
image

However, would the whole purpose of TSubclassOf be nullified by just writing:
UPROPERTY(EditDefaultsOnly, Category=Damage)

UDamageType DamageType;

To me this is the same thing?

That is not the same thing, no. TSubclassOf holds a type whilst what you would have would be creating an instance of that type. (You also can’t create UObjects on the stack).

It’s the difference between (note this isn’t valid)

SomeType Type = int;

And

int Value = 5;

Thanks Dan :slight_smile:

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

Privacy & Terms