I was looking on how to restore the console. Created a function called InitializeConsole
in my GameInstance class:
void MyPewPewShooterGameInstance::InitializeConsole()
{
UWorld* World = ();
if (!ensure(World != nullptr)) return;
auto* Viewport = World->GetGameViewport();
if (!ensure(Viewport != nullptr)) return;
if (!Viewport->ViewportConsole)
{
Viewport->ViewportConsole = static_cast<UConsole*>(UGameplayStatics::SpawnObject(UConsole::StaticClass(), ()->GetGameViewport()));
}
}
When you call it, you have to make sure that the Viewport already exist on the game world i.e. it won’t work if you call it from inside of the constructor of the game instance because at that point in time viewport is still null in the world.
For now I just call it from BeginPlay of my game mode, which is sufficient enough for now. Dunno what would be the proper place to call it, since everything can change technically: game mode, level, player controller, etc. And I need to make sure that I call by the time ViewPort exists.