Spawning actor from client doesn't replicate on server

Hello, I’m lost. I’ve been watching and reading a lot about replication and networking fundamentals in ue4 blueprints. Been spending days trying to solve this issue and I’m now desperate.

I’m trying to make a game where both players spawn their units from their own camp. Right now I already have a simple issue trying to spawn anything from the client side.

When pressing ‘F’ key on client it doesn’t spawn (on either machines) when set the event on “Run on Server”
On the other hand when pressing ‘F’ key on the server it spawns successfully for both.
This is called from my BP_Spawner actor and this actor is set to “Replicates” so is my unit spawning.

Now changing the event to “Multicast”
When pressing ‘F’ key on client it does spawn but only on the client and of course they’re not moving because they don’t exist on the server. And when pressing ‘F’ on server it works like normal but shows 2 not moving units plus 2 normal moving ones on the client.

Also another not so important problem is when spawning from server side where it’s working for both machines. The color doesn’t apply on the client side. Even tho my Enum var “Player” is replicated.

Hi,

Right now I already have a simple
issue trying to spawn anything from
the client side.

If you spawn something on a client, all other clients and the server will never know about that. If you want all clients to know about something, it needs to happen on the server. So you should spawn your units on the server.

When pressing ‘F’ key on client it
doesn’t spawn (on either machines)

The only client that can call RunOnServer events on an actor is the client that owns that actor, if any other client tries to do so then nothing will happen. And there can only be one owner. So you could move RunOnServer events either to the player controller or the controlled pawn (which a client owns by default), normally for player input you would put that into the player controller.

The color doesn’t apply on the client
side. Even tho my Enum var “Player” is
replicated.

You can do some prints to try pin it down, might be cause you’re doing this in the ConstructionScript.

by controlled pawn you mean the player
right?

Not sure what you mean with player, I meant the pawn that your player controller is possessing. In an RTS that would just be something like a camera that can move around.


Your image above is close, but you again call the RunOnServer event not on the player controller, but on the BPSpawner which won’t work unless this clients owns them.

What you could do

So you need to call the RunOnServer event on the player controller.

Thank you so much for responding!

by controlled pawn you mean the player right?

I don’t really understand how to solve my issue. Could you maybe show me an example of what you mean? I changed to my controller but still doesn’t work. From my BP_PlayerController I call a spawn unit on my server.
It doesn’t spawn when I press F on my client.

1 Like