Spawning only works for server

Hello.

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.

This is the PlayerController:

(ClientPostLogin replicates “Run on owning Client” and is reliable)

This is the GameMode (the relevant part):

(VehicleSpawn replicates “Run on server” and is reliable)

I’m scratching my head at this point. :confused:

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:

player_controller.png

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.

Hope it helps!

Okay, so if I got this straight:

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.

Ok, I tried this:

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.

It depends on what you’re trying to do. Why don’t you just assign the vehicle actor as the default pawn class at the Game Mode?

You could also set it to replicate at the actor blueprint, don’t need to call SetReplicates everytime it spawns.

I’d like to have a vehicle selection at some point, that’s why I’m trying to spawn it.

Also, yes, I forgot the replicate node there. :slight_smile:

Hmm seems like it should work fine. Did you remove the “Vehicle Spawn” from the ClientPostLogin?

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.