Please Explain this code

Please Explain me this:

UWorld* TheWorld = GetWorld();

if (TheWorld != nullptr)
{

AGameModeBase* GameMode =
UGameplayStatics::GetGameMode(TheWorld);
AMyGameModeBase * MyGameMode =
Cast<AMyGameModeBase>(GameMode);

}

I want to know that what these (listed below line1 , Line2 , line3) lines do in the code above.

UWorld* TheWorld = GetWorld();    //Line1


AGameModeBase* GameMode = UGameplayStatics::GetGameMode(TheWorld);    //Line2



AMyGameModeBase * MyGameMode = Cast<AMyGameModeBase>(GameMode);   //Line3

Thanks in advance…

  1. Gets a reference to World. It’s occasionally needed for various functions, and GetGameMode() is one of them.
  2. Gets a reference to the GameMode that’s selected in your Project Settings. But since this function gets the GameModeBase, you need to 3:
  3. Cast it to your specific GameMode in order to access its specific functions and Variables.