Can you convert an actor into a pawn in C++?

I know you can do this in blueprints by changing the class a blueprint is derived from, but I don’t know if this is possible in code.

Same way. In C++ when you define an object you also define what it derives from, if anything.

class AMyActor : public AActor

In this case AMyActor is derived from Actor. If we wanted to derive from pawn instead, we just do this:

class AMyActor : public APawn

Now it has all of the characteristics of Actor and Pawn, since Pawn derives from Actor.

If you want to see if an actor derives from APawn, you can just cast like


Or if you don’t need to access Pawn properties, you can check with IsA:

if (MyActorPtr->IsA(APawn::StaticClass())

That worked perfectly, thanks!

Yay! I’m glad. Cheers.

1 Like