Why use TSubClassOf and not just the class itself?

I said “same as” not “are the same”, by that i mean they function exactly the same due to C++ magic :stuck_out_tongue: I’m fully aware this is template class that have cast overload to UClass*, the class contains only UClass pointer so in memory sense it makes no difference from normal UClass*. Only diffrence is that with TSubclassOf compiler pastes code on value get via inline that checks is class is related to class defined in template. You can look up here:

https://github.com/EpicGames/UnrealEngine/blob/f794321ffcad597c6232bc706304c0c9b4e154b2/Engine/Source/Runtime/CoreUObject/Public/Templates/SubclassOf.h#L75

But it really make no difference how do you use TSubclassOf and UClass* you use it the same way, it’s made so you don’t need to think that much about it.

If you want to pick on details ScottSpadea actully said something wrong “class pointers and object pointers are different things” all pointers ARE the same in C++, UClass IS object pointer as UDamageType pointer is object created by engine (not editor) on start up to identify class in UE4 reflection system and practically any pointer (not just object) as in reality all of them are just memory address integers. StaticClass() is a function which get you UClass* of specific class from generated code (each class have individual StaticClass() function declared and defined).

What ScottSpadea wanted to say is that they managed differently UClass is created by the engine on start up and it will be there until engine dies, it no different then any other object created by the engine which engine controls, while your class need to be initiated by yourself. So only difference is there life cycle and what is managing it. Still i use class pointer and object pointer term myself so… ;p engine design kind of force it in