How to fix actor spawning twice on client side?


In the upper blueprint the actor is spawned twice (I think the server and client spawns it). So I used a switch has authority and the below blueprint so only the server spawns it, however, the exposed variable ‘Damage’ inside the actor blueprint can only changes its values if set to replicate. But I’m not sure If I can set to replicate, because each player has it’s own value, depending on what level the player is. How can I properly spawn the actor just once in the server and client side?

Hi @Pinteco

Replicating a variable doesn’t imply making all instances of the actor with that variable have the same value. It means that when the server changes its value, all clients will receive the information that the target actor has changed its variable’s value.

In a multiplayer game, the server should always be the one in charge of calculating how much ammo a Player or NPC has, how much damage they should deal, and basically all important data.

For things like ammo, its better to have it replicated, so the server changes its value, and tells the client to update their ammo to the correct value.

On the other hand, ONLY THE SERVER should spawn actors. The only exception is when you want a client to see something only relevant to them, like a VFX, Widget, sound, …

Damage should also be replicated, so the server always knows how much damage each character can deal.

Usually for this case, you want the client asking the server to shoot. Then the server checks if the client has enough ammo. Then the server spawns the projectile, if the projectile is spawned, you subtract the ammo, and since its replicated, the client updates the value too.

make sure the firebolt is set to replicate and replicate movement too

@TrueFranco this way is still spawning the actor twice :confused: unless I did something wrong

if your firebolt is set to replicate dont multicast it, if its just FX then dont replicate but do multicast it

@Auran131 by ‘firebolt’ do you mean the actor to spawn? I set it to replicate because otherwise I couldn’t make the particle system visible to all players.

then you dont need to multicast which is why you get duplicates. just spawn it on server.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.