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 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!

Thanks for taking the time out! Here it is

Can’t find any crash in there, you sure this is the right one?

Yeah it is. When it crashes, I get this message:
You do not have any debugging symbols required to display the callstack for this crash.

When I look inside the Game\Saved\Crashes\ folder, this is the one that was updated at the time of the crash, so I believe it must be this one.

Check out the Game\Saved\Logs folder, and look for the one that was created at the time of the crash. I usually look at the logs in there, not sure if it makes a difference though…

Here is the one in Game\Saved\Logs folder

Better! :wink:

APSprayWeapon::Tick() [h:\github\stanion studios\undertow\paintgame\source\paintgame\private\weapons\psprayweapon.cpp:74]

Check out this line in your code. You’re game is throwing a EXCEPTION_ACCESS_VIOLATION. I guess you’re trying to access a nullpointer somewhere.

Ooh yeah I see that and I know what the issue is now. The gun that the default character is holding doesn’t get destroyed with him and that references its “OwningPawn” in the tick function. I tried to implement a fix right away but it goes a bit deeper - that reference, and is going to take some time, so I just thought I’d pop back in here and thank you for all the help. That almost certainly is the root cause. I really appreciate you taking out the time, I had been stumped over this for quite some time :slight_smile: cheers

You’re welcome, glad you were able to find your problem :slight_smile: Make sure to check your log files in the future, they can help you save a huge amount of time!
Not sure if this is possible since it’s all just comments, but would be cool if you could somehow mark this as an answer :smiley:

Sure yeah I’ll do that if you “convert this comment into an answer” from the drop down next to the reply.

Ah, now I know! Thx :slight_smile:

Any log data maybe?