In main menu I added a way for the players to choose their character, and when they do, it is saved inside the game instance.
When the player joins a server the right character is spawned, but I have a problem when the map is changed. For that I’m using seamless travel, and when the next map is loaded, every player has the same character as the host and not the one they choose, like when they first join the server.
Inside the GameMode
I have this:
And inside player controller:
What do I need to change in order for the right character to be spawned after server travel?
I switched from the above spawning method to a Spawn Actor From Class / Possess
method as this gives me more control over where to spawn/respawn the player based of a team location where is the case.
Inside PlayerController
:
Inside GameMode
(in the bellow example it will spawn them always at first PlayerStart
, and it isn’t set for a specific team):
At Spawn Actor From Class
you can set your own rotation and scale beside the location of the spawn. Or if you want to change to another character but keep the same location where the player was at the time of the call and not send the player back to the start, instead of using the Get Actor Transform Location
from the PlayerStart
, you can save the location of the actor before destroying it, and use that as the location of actor Spawn Transform Location
.
Then on the map blueprint that you switch to:
Example to switch character on same location:
You can add to this, so that the camera remains the same or what else you want. This is just a basic swap. Respawning a new actor I think is recommended because if you just switch the skeletal mesh you can get into the problem where the old materials are still used on the new skeletal mesh, and so the actor will look really weird.