Is there a way to change the Default Pawn in Game Mode for the Player Start before the level is loaded? I’m working on a multiplayer game where each player can select a unique character, and then when it switches from the Select Screen level to the battle arena level, it spawns the selected characters. However this only works for every player except Player 1, who is stuck with the Default Pawn regardless of which character they actually selected.
Set default pawn to none for all.
Spawn the various player classes that are selected and then have the player possess that spawned character.
Didn’t work. I set the GameMode’s default pawn to none, spawned the four characters and and set all four controllers to possess each respective one. However, Player Controller 0 throws an Accessed None error. It look as if it’s still trying to spawn the Default Pawn, and because it’s set to none it is getting confused and not even getting to the possess command.
I’m not sure. cuz I do it differently. But I don’t think you want to be using Player Controller 0. Are you spawning the actors and possessing them from the GameMode BP?
So you’re doing something like “get player contoller index 0” casting to player controller and then using that to possess?
I don’t think getting players at indices are very reliable in multiplayer.
Create a custom player controller bp as a child of Player Controller.
Every player will have their own player controller BP.
As a server function, spawn and possess inside the custom player controller BP.
I create a custom GameInstance as well. This is where I set the Char selection int. Because the Custom Player Controller is wiped each time the player dies. If you store variables in here. they will get cleared out. GameInstance variables persists so you can respawn them with the same selected character.
Then cast to custom game instance from the Custom Player Controller to get that Int. Then switch on int to tell which char to spawn and possess.
So dumb question, but how do I get these custom controllers into the level so that I can spawn the characters? Spawning them as actors doesn’t seem to work, the gamemode only creates one type of controller, and create player doesn’t offer an option.
in your project settings in maps and modes, change the player controller to the custom player controller to “use it”.
You’ll still spawn the characters as actors but do it inside the custom player controller and possess it from inside there as well.
I dont have time right now to simplify it but just try on your own.
- create custom player controller as a child of player controller
- set your game mode to use the custom one in the project settings
- in the custom player controller spawn the character actor and then possess it
- work on adding different characters later for now just get it to work with one
Each player will have their own version of the custom player controller. You only have to MAKE one. but they’ll each get a copy. hence you need to pipe an int variable into it when they join the game to tell their copy of the custom player controller what character number to spawn. In your char select widget you can have that cast to the custom game instance and set the character number there. Then from the custom player controller cast to the custom game instance and get the char selection int and use that to decide which character actor to spawn.
Make sure you are creating the Player Start actor inside the Persistant Level (click on view -eye- button and see if it vanishes with persistant level to be sure). I solved it by doing that and deleting other player starts.