Turn the First Person FPS Template to a Multiplayer experience

Now lets inform the other clients that the blueprint is running some animations and sounds.

We will add a new Custom Event, lets call it “Multicast Fire” and set the replication on this custom event to “Multicast” then lets connect it to the Montage Play line of our blueprint. We need to summon this event from the server side, because the server is the only one that can fire multicast events. So in this case we need to summon it after the RPC Fire event we created earlier.

If you play the game now you will see the animations playing correctly on both windows.

We are getting nearer, but further testing of the game will show you that the client is not informing about the pitch of the weapon and consequentially all projectiles are spawned pointing forward.
This is expected too, the server spawned the FirstPersonCharacter blueprint with the weapon pointing forward and it assumes that it hasn’t change it position even if you change it on the client. Now lets replicate some variables.

Create a variable called “WeaponPitch” and assign a rotator type to it, change the Replication select box from None to Replicated.
Paso08.jpg

Now we need to set the value of the World rotation of the First Person Camera to this new Variable but at the server level, this can be achieved by passing the value of the rotation of the camera to the RPC Fire custom event and then pass it to the Multicast Fire event. Do this by creating a parameter in both events of the type rotator. After we pass the value through both events we will set the value to the new created variable. Lastly we will get the value of the variable connecting it to the required nodes.

Now when playing the game you will see the projectiles spawning in the right direction, we are getting closer but no candy. The weapon itself is not showing any pitch on other clients or server. We need another event that fires up every time we change the pitch of the weapon.