Download

[UE4.24] Question about GetPlayerController

Hi all. I want to implement a function to open a new map in a Slate Widget class



void SMenuWidget::EnterGame()
{    
    UGameplayStatics::OpenLevel(UGameplayStatics::GetPlayerController(GWorld, 0)->GetWorld(), FName("NewGameMap"));
}


but, it’s crashed. The reason is UGameplayStatics::GetPlayerController(GWorld, 0) return null

why is this?

Thanks for any thoughts!