I’m trying to spawn an actor (and possess it) after the player connects, but only the server spawns it. The client remains in the default state, with the DefaultPawn.
The Game Mode is only visible server-side, you’re getting a null when you try to access it client-side at the top picture:
You should, at the same class as the top picture, create a custom event that executes at the server, doing the same logic as you did in order to possess.
It should work, since the player controller is visible for both the server and the client.
I’m taking the custom event (VehicleSpawn) from the GameMode and moving it to PlayerController and then I’m executing that custom event on ClientPostLogin?
You don’t even need move anything. Simply, override the event “OnPostLogin” on GameMode, and as soon as someone logins, spawn a vehicle and posses it to the new player. Then you can send him your custom ClientPostLogin to create the HUD and other client data you may have.
One actor is spawned and gets possessed by the server, but as soon as the client connects, it spawns another actor, the client possesses it, but the server gets unpossessed.
Yeah, I did. If I remove the Possess node and directly hook up the New Player pin from OnPostLogin to Owner at the SpawnActor node, the roles reverse: the server is working good, but the client gets depossessed.
The Event OnPostLogin will always be called whenever a player joins the session. If you spawn the actor(and possess) the moment a player is entering the game you wont control which vehicle will spawn unless it has been defined before by the player.
If you want to control **WHEN **you spawn the vehicle (after the player has selected the desired vehicle), you gonna need to spawn and possess in another moment, probably when all has been defined beforehand. For doing this, it doesn’t matter much if the GameMode will handle this or the PlayerController (you choose what fits better for you), but keep in mind to leave this to the Server.
Quick question:
The player will select his vehicle before or after entering the map?
Well, for now I set it up to spawn/possess the vehicle on keypress (in PlayerController), after the client has connected and it works great. I would like to assign players and vehicles before the level has loaded (in another map), and then spawn each vehicle to its respective player.