Download

Destroying actor after server travel crashes game.

Been scratching my head over this one and can’t seem to figure it out. This is what I’m trying to achieve:

  1. Select character in the lobby
  2. Seamless travel to the game level
  3. Assign the selected characters.

So the player selects his character while in the lobby. When the timer runs out, I do this:

FString mapsPath = TEXT("/Game/Maps/") + mapName;
bUseSeamlessTravel = true;
GetWorld()->ServerTravel(mapsPath);

A question at this point - Am I supposed to explicitly mention which players to take over to the next map? Like I keep seeing GetSeamlessTravelActorList pop up every now and then but I’m not sure how to use it.
Anyway, doing this successfully takes me the actual gameplay map. Once in there, I call this function in the GameMode class, which spawns the selected character, assigns the controller to this character, and destroys the old, default one.

void APGameMode::SpawnCharacterSelections()
{
APawn* CurrentChar;
APPlayerController* CurrentController;
TSubclassOf<APCharacter> Selection;

for (FConstPlayerControllerIterator Iterator = GetWorld()->GetPlayerControllerIterator(); Iterator; ++Iterator) {
CurrentController = Cast<APPlayerController>(*Iterator);
if (CurrentController)
{
CurrentChar = CurrentController->GetPawn();
CurrentCharacter = CurrentController->GetOwner();
Selection = Cast<UGameInstance>(CurrentChar->GetGameInstance())->GetSelectedCharacter();
//CurrentController->UnPossess();

//CurrentChar->SpawnDefaultController();
FActorSpawnParameters ActorSpawnParams;
ActorSpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;

APCharacter* SpawnedCharacter = GetWorld()->SpawnActor<APCharacter>(Selection, CurrentChar->GetActorLocation(), CurrentChar->GetActorRotation(), ActorSpawnParams);
CurrentController->Possess(SpawnedCharacter);

CurrentChar->Destroy();

}
}
}

Now, I’m testing this in standalone mode, and the game crashes about 30-40 seconds in the level. I’m not sure what’s happening. Lobby and the game level have different game modes, could that be the reason? Although if that were the case, I’m not sure how that explains these observations : 1. If I do everything the same and just don’t destroy the default character, the game doesn’t crash. 2. If I destroy the default character/actor (CurrentCharacter in code), the game crashes as soon as the level after lobby is loaded 3. If I destroy the default Pawn (CurrentChar in code), the game crashes about 30-40 seconds later.

Don’t know what’s wrong, any help or a nudge in the right direction will be greatly appreciated. Thanks!