skip to content
Tiny Game Dev

Safe casts in Unreal Engine

How to safely cast between pointer types.

Actor to Character

Say you have a pointer to an Actor and you’d like to cast this to a Character so you can call your function. Unreal has the Cast function template to do this safely:

ACharacter* Character = Cast<ACharacter>(GetOwner());
if (!Character)

In the above case GetOwner() returns an AActor* which the Cast turns into a nullptr if it’s not an ACharacter (or a child) object.

That is all.

Join our mailing list and hear about exclusive content like closed beta tests first. We don't mail often.