4

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?

Guest102
  • 49
  • 1
  • 2

1 Answers1

3

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

Cast<MyCustomPlayerController>(InController)->MyCustomPlayerControllerVariable
sam hocevar
  • 23,811
  • 2
  • 63
  • 95