# Weapon Sway function Replication

**URL:** <https://forums.unrealengine.com/t/weapon-sway-function-replication/477444>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [January 19, 2021, 1:37am UTC](https://forums.unrealengine.com/t/weapon-sway-function-replication/477444 "2021-01-19T01:37:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_8bd91971](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8bd91971](https://forums.unrealengine.com/u/anonymous_user_8bd91971)\
**Post date:** [January 19, 2021, 1:37am UTC](https://forums.unrealengine.com/t/weapon-sway-function-replication/477444/1 "2021-01-19T01:37:18Z")

</div>

Hello, I have a Weapon Sway function that runs on Event Tick and propagates from server to all clients:

 ![327488-characterbp-swayevents.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/0/5/d0598ed54eb02cb48c737670e2d7dda16321ca53.png)

It works while on Server or Client, however, it doesn’t trigger when another **Client is Spectating (while using SetViewTargetWithBlend) the selected Player,** here’s the final function which is being run on the **Multicast Event:**

 ![327489-characterbp-swayfunction.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/c/7/bc7c1bd6b49cb1b4a7a22e76dfd31c2fdd955796.png)

So it is working on the Server and Owning Client, but it appears that other Clients aren’t getting the feed.

Also, I have the **WeaponSway Component set to Replicate, as well as the variables used.**

Appreciate your help, thank you.

---

<div class="post-metadata">

**Author:** ![Mattk50](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mattk50](https://forums.unrealengine.com/u/Mattk50)\
**Post date:** [January 19, 2021, 3:09am UTC](https://forums.unrealengine.com/t/weapon-sway-function-replication/477444/2 "2021-01-19T03:09:09Z")

</div>

Something like weapon sway should pretty much never be replicated and definitely not replicated with a multicast on tick, that’s going to destroy your network for no good reason.

Instead you should just run the weapon sway code locally on each client. Assuming you are using the base character, the player’s rotation is already replicated. A very important rule of thumb when designing for multiplayer is that if you can, you should always base effects on existing signals from the server instead of trying to replicate something new. The cost of re-simulating a couple blueprint nodes is tiny compared to the load you on the game from using a ton of replicated variables.

So, if you have the rotation already replicated on the character (if you don’t yet, you may need to set that up properly), so you should just run the sway calculations on every client on tick. Which is as simple as just connecting the sway code to the tick, no multicasts, run on server etc should be involved anywhere.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8bd91971](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8bd91971](https://forums.unrealengine.com/u/anonymous_user_8bd91971)\
**Post date:** [January 19, 2021, 7:49pm UTC](https://forums.unrealengine.com/t/weapon-sway-function-replication/477444/3 "2021-01-19T19:49:48Z")

</div>

Thanks for the tips. Yes, I’m running the code locally without the OnServer and Multicast Events, I thought it would work if I used them.

Still, it’s pretty odd that it doesn’t work, whereas if use something like this inside the function and connecting it to the Event Tick directly, it replicates fine while spectating:

 ![327586-weapsway.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/c/6/4c6b288ffc4c0695dc7ebb410565725fb8c1e1d6.png)

So it must be something related with the code from the original weapon sway? Maybe some variable that is not replicating correctly?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8bd91971](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8bd91971](https://forums.unrealengine.com/u/anonymous_user_8bd91971)\
**Post date:** [January 19, 2021, 11:16pm UTC](https://forums.unrealengine.com/t/weapon-sway-function-replication/477444/4 "2021-01-19T23:16:40Z")

</div>

From what I could get, it seems the problem comes from the **GetLookUp** and **GetTurn** input nodes, cause if I use a **RandomFloatInRange** it works just fine

 ![327606-weapsway1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/5/0/e506aef37d2f2b0688da228323723c890d043501.png)
