How to get spawned class reference?

Hello avere one ! Please help me with this qustion.

i have code for spawn PlayerCharacter. I need get Player reference for use in GameMode.

	UWorld* const World = GetWorld(); //Ссылка на мир
	
	if (World)
	{
		FActorSpawnParameters SpawnParams;
		AEOnlineCharacter* Player = World->SpawnActor<AEOnlineCharacter>(CharacterBP);
		
		GM->GetCharLocation();

		//Получаем управление над заспавненым персанажем
		Possess(Player);

	}

this reference located in Player Controller in Begin play. I need get this reference in GameMode. how can i do?

i need get acces to class Player.

I’m not understanding your question, this AEOnlineCharacter* Player should be what you need?

In game mode .h file under public:, create a place to hold the pointer, such as

MyCharacterClass* MyCharacter; 

where MyCharacterClass is the class you’ve extended from ACharacter to be your character.

Then in BeginPlay of your player controller, you should be able to do something like the following:

MyGameModeClassPtr->MyCharacter = Cast<MyCharacterClass>(this->GetPawn());

which will place a pointer to your already possessed character into your GameMode class. MyGameModeClass is the class you created from AGameMode. Because of timing, be sure to test if MyCharacter exists/is not null prior to trying to use it in GameMode. You should then be able to use functions within your character class from GameMode.