Any Game State good example?

Sure Natalo77:

First of all, I’ve the GameModeBase class. I initialize both the GameState and the PlayerController on the constructor:

AVertiportSimulatorGameModeBase::AVertiportSimulatorGameModeBase()
{
	PlayerControllerClass = ASimulationController::StaticClass();
	GameStateClass = ASimulatorState::StaticClass();
}

Secondly, on BeginPlay, I setup my Game and I add the Vertiports objects to the GameState array. This is working just fine:

void AVertiportSimulatorGameModeBase::BeginPlay()
{
   Super::BeginPlay();
   UWorld* const World = GetWorld();
   // More setup ....
   if(World)
   {
        //Some more conditions....
        //Then I instantiate a Vertiport Object 
        AVertiport* Vertiport = World->SpawnActor<AVertiport>(AVertiport::StaticClass(), FVector(0,0,0), FRotator(0,0,0));
	    Vertiport->Initialize(vertiport.NoOfPads, FVector(vertiport.Longitude,vertiport.Latitude,vertiport.Height), FVector(0,0,0));
        //
		GetGameState<ASimulatorState>()->GetVertiportArray().Push(Vertiport);
   }
}

Then, in the SimulatorController, I’m trying to access the GameState when a key is pressed:

void ASimulationController::ChangeCamera()
{
	GLog->Log("Pressed!");
	UWorld* World = GetWorld();
	TArray<AVertiport*> VertiportList = World->GetGameState<ASimulatorState>()->GetVertiportArray();
	GLog->Log("Array!");
	for(auto &item : VertiportList)
	{
		
		if(!item->GetCamera())
		{
			GLog->Log("Activating!");
			item->SetCamera(true);
			UGameplayStatics::GetPlayerController(GetWorld(), 0)->SetViewTarget(item);
			break;
		}
		item->SetCamera(false);
	}
}

Debugging (with a break point just after the Lot(Array)) and evaluating the elements in the array, I get these issues:

Captura de pantalla 2022-02-04 a las 21.04.41

Array elements are 0, while 2 Vertiports were added to the vector in the GameBase. Also, World is not available, which looks worse to me…

Any idea? Thank you very much for your help!

Best,