During these cold winter days I am studying Unreal Engine 5. At first it looks a bit intimidating, but one step after the other and things are starting to make sense. I am having a lot of fun studying it! If you are curious about it, I think that it is totally worth investing some time learning it, even if it has a quite steep learning curve in the beginning.
This is a short post, but I thought it was mandatory in order to help some beginners like me. This is particularly useful if you are working on a multiplayer project or in a game where you can spawn your Pawn/Character in different locations. You start putting multiple Player Start actors, you configure your Level Blueprint in order to set the Pawn/Character to a custom location after your Event Begin Play, and in your editor everything just works fine. And it is great! But there is a problem.
The problem is that, when you build your project for shipping and you run your newly compiled executable, your Pawns/Characters start spawning randomly. Not great, right?
I scraped the Web for hours and everything I found was some suggestion to set your custom Game Mode, double check that your Pawn/Character does not possess a Camera somewhere in the scene, but nothing seemed to solve my issue. Everything was fine and I didn’t figure out why it wasn’t working as it was supposed to work!
The problem is that the Event Begin Play from every Blueprint runs simultaneously with the built-in function Choose Player Start from the Game Mode. In computer science “simultaneously” does not make sense (if you are not in a multi-threading environment!), so the point is that there is some kind of race condition. In my case, inside the Editor Choose Player Start was running before the Event Begin Play, making the code I put in Event Begin Play run flawlessly and changing the player’s position without issues. Inside the shipped executable, the Choose Player Start was running after the Event Begin Play, overriding its behaviour and choosing a random Player Start in the scene. This is why I was going mad.
The solution is quite easy: if you have to set your player’s position from the beginning, do it overriding the default Choose Player Start function.
Open your Game Mode. In the Functions menu, click on Override drop-down that appears near the plus sign when you hover your mouse on it, and click on the
ChoosePlayerStart choice from the drop-down.
If you want to simply set the default player start location to the first appearing in the World Outliner, you can do exactly as follows:
That’s it! Compile & save, everything should work fine now. The solution provided is just an hint, it does not handle specific conditions (image what happens if you do not have a Player Start in the scene and you are accessing the first one), I consider it a “quick start” for helping you finding the solution that best fits your needs.
I plan to continue my journey learning Unreal Engine 5, so hopefully I will post more content about this engine in the future.