I am currently developing my first classes in Unreal Engine 4. Coming from using UScript extensively, I'm getting a little bit confused by how typecasting works in pure C++. More specifically, class/object casting.

I am currently putting together a switch statement in MyCustomGameMode which calls upon MyCustomPlayerController for MyCustomPlayerControllerVariable.

The function in question that I am overriding is this one: virtual UClass* GetDefaultPawnClassForController(AController* InController);

Currently I'm trying to call the variable with the following line of code, which I know is incorrect, but I'm not sure why:


I am interested in casting the "InController" to MyCustomPlayerController but Cast<MyCustomPlayerController>(InController) doesn't seem to work, what am I doing wrong here?

  • \$\begingroup\$ I flagged this as normal programming question, but i was wrong. It is related to game programming as this is UScript. \$\endgroup\$ – Katu Jul 1 '14 at 6:08
  • \$\begingroup\$ @Katu it’s definitely not UScript; the author just said he/she was used to UScript from UE3. \$\endgroup\$ – sam hocevar Jul 1 '14 at 7:06
  • \$\begingroup\$ So is it supposed to be 100% true C++ or some dialect with almost identical syntax? \$\endgroup\$ – Mario Jul 1 '14 at 7:12
  • \$\begingroup\$ @SamHocevar Yeah, yeah. Should not come here before morning coffee. \$\endgroup\$ – Katu Jul 1 '14 at 7:12
  • 2
    \$\begingroup\$ @Guest102 “is incorrect”, or “doesn’t seem to work” is not a helpful description of your problem. Be more specific. \$\endgroup\$ – sam hocevar Jul 1 '14 at 7:17

Cast<Foo> returns a Foo *. So the proper way to access your variable should be:


Not the answer you're looking for? Browse other questions tagged or ask your own question.