Solving the car spawning problem

So while waiting for new lectures I decided to dive into the code and look for the cause of the issue where sometimes not all cars will spawn if two or more player instances are started. Increasing the number of spawn points (as in the lecture) helps, but it’s not a real solution; the issue just occurs less frequently with more spawn points.

As it turns out, the root cause is the default spawning behavior in AGameModeBase, and there are two parts to the issue:

  1. Of all the spawn points in the world, each player pawn is assigned one at random. Unfortunately, sometimes two players are assigned the same spawn point. (See AGameModeBase::ChoosePlayerStart_Implementation)
  2. When spawning player pawns, the SpawnCollisionHandlingOverride setting in the actor spawn parameters is not set, and the default seems to be a setting that aborts spawning if the location is blocked. (See AGameModeBase::SpawnDefaultPawnAtTransform_Implementation)

I managed to solve this by overriding the SpawnDefaultPawnAtTransform_Implementation method in the game mode, pretty much copy+pasting the code from AGameModeBase but adding the following setting to the SpawnInfo:

SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;

This makes sure that the cars always spawn, although two cars may now spawn right next to each other if they share a spawn point. A more ideal solution would be to make sure each car gets its own spawn point.

Thanks for taking a look into this, MadDogX. I think it needs a solution like a while loop.

Hello how did you override this function ?
can you show me actual code?

Privacy & Terms