I am working on a local co-op game with two players and I am having an issue with Local Player spawning when changing or restarting levels.
When I start the game, everything works correctly and both local players are spawned as expected. However, when I open a new level using Open Level by Name, or restart the current level, the Local Players are created again, resulting in duplicate players.
For example:
Level 1 starts with Player 1 and Player 2 correctly.
I open Level 2 using Open Level by Name.
The new level creates the Local Players again, causing additional Player Controllers / characters to appear.
If I restart or change levels multiple times, the number of players can increase.
I am using Unreal Engine 5.6.1 and the game is a local co-op game.
My question is: What is the correct way to handle Local Players and Player Controllers when changing levels in a local multiplayer game?
Should the Local Players be created only once and preserved between levels, or is there a recommended way to prevent GameMode / BeginPlay from spawning duplicate Local Players after Open Level by Name?
Any advice on the correct architecture for handling local co-op players across level transitions would be greatly appreciated.
The Event Init node runs when the Game Instance is initialized at the start of the game. Unlike the GameMode, the Game Instance is not destroyed and recreated when changing levels, which makes it a good place to initialize elements that should persist throughout the entire game session, such as the creation of the Local Player in this case.
I would also recommend adding a Delay Until Next Tick before creating the player. This node simply waits one frame before continuing execution. In this case, it is useful because if you create the Local Player immediately during Event Init, Unreal may not have finished initializing everything it needs yet. By waiting one tick, you give the engine time to complete its initialization process, ensuring that the Local Player is created correctly and can receive input without issues.
After creating your Game Instance Blueprint, you need to assign it in Project Settings -Maps & Modes - Game Instance Class. Otherwise, Unreal will continue using the default Game Instance and this logic will never be executed.