# Unreal Engine 4 — Casting [closed]

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:

Cast<MyCustomPlayerController>(InController).MyCustomPlayerControllerVariable


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

## closed as unclear what you're asking by sam hocevar, Josh♦Jul 1 '14 at 15:56

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

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

Cast<Foo> returns a Foo *. So the proper way to access your variable should be:
Cast<MyCustomPlayerController>(InController)->MyCustomPlayerControllerVariable