Get Player Controller from inside Game Instance?

Hi everyone!
I’m trying to cast to my Player Controller inside the Init() in the Game Instance.
The thing it always fails. The PController is APCBase, and it’s already defined as the default controller.

Like this:
APCBase* const PC = Cast (UGameplayStatics::GetPlayerController(GetWorld(),0));

I tried using
UGameplayStatics::GetPlayerController
GetPrimaryPlayerController
GetFirstLocalPlayerController

Is there something I’m missing?

Your Game Instance is instantiated before the World and before the Player Controller, that’s probably the reason why – you’re calling something that doesn’t exist yet. You probably have to revisit your logic a bit!

I found the solution if anyone is trying the same.
The thing is that World() dont exist in the game instance.

I used
FCoreUObjectDelegates::PostLoadMapWithWorld.AddUObject(this, &UC0GameInstance::OnPostLoadMap);

This will call OnPostLoadMap after the map Loads. Then we’ll have the World.
In the OnPostLoadMap function I use:
APCBase* const PC = Cast (UGameplayStatics::GetPlayerController(GetWorld(),0));

To cast to my specific Controller Type.

The thing is that it only works on the packaged game.

Thank you Fraps! I didnt know that before.