Hi there,
I’ve got a custom class that derives from GameState. I have a function to advance the game to the next “phase”, which should spawn a new controller and switch the player to this controller.
When I try and create a new controller via the NewObject function, the game instantly crashes and this is printed to the output:
Fatal error: [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.6\Engine\Source\Runtime\CoreUObject\Private\Templates\Casts.cpp] [Line: 11]
Cast of Class /Script/FantasyStrategy.PlayerUnitController to Level failed
UE4Editor.exe has triggered a breakpoint.
And the code in question…
auto instance = (UOlusiaGameInstance*)GetGameInstance();
APlayerUnitController* newController = NewObject<APlayerUnitController>(APlayerUnitController::StaticClass());
instance->GetLocalPlayerByIndex(0)->SwitchController(newController);
Currently a little rough around the edges as I have been attempting to get some sort of solution.
Is there any reason I cannot instantiate a new controller? I have tried in my GameMode derivative too, with the same error.