Cast UClass to Actor Class[Not Objects]

For some reason Im having great difficulty in casting a UClass to an Actor Class.

Im basically looking for the C++ equivalent of this blueprint node.

73637-classcast.png

There is no way to “cast” a UClass to another UClass. UClasses don’t inherit from each other like the classes they describe do.

What you can do is use TSubclassOf. E.g.

UClass* MyClass = /* some class here */

TSubclassOf<AActor> ActorClass = MyClass;

if ( ActorClass != NULL ) 
  do stuff;

or

UClass* MyClass = /* some class here */

if ( MyClass->IsChildOf( AActor::StaticClass() ) )
  do stuff;

In general, it’s always a good idea to use TSubclassOf<> variables instead of direct UClass vars.

4 Likes