Blueprint networking - Projectile Firing Weapons

Hello, I am trying to understand how to set-up my weapons system.
What I have done:

Created a method that is called on the server in my character blue print which calls a method from a weapon:

31670-screenshot1.png

Created a basic blueprint with a fire event this (method would contain the calculations of rotation as well as direction), as well as another event for a child to override. The purpose of this blueprint is for weapons to inherit from:

In the child blueprint of the basic weapon blueprint I have the event that is overridden and from here I would call the event in the parent blueprint x amount of times depending on its weapon type ie a shotgun may call the method fire 5 times in a spread cone.

The issue I have run into is when using RPC to fire the weapon, it will only do the calculations of firing for one of the players, if I change the number of the player index it will do it for the other. Both clients will call the event and projectiles will both fire however it will only ever take into account a single player (dependant on the player index).

I have been looking for answers regarding this and I have come across player state and the variable it contains, PlayerID. Here is what I thought I should do with it:

  • pass the player id to the server
    when fire is called
  • on the server
    gather all players via find all
    actors of a particular instance
  • loop through all these actors until I
    find one with the matching player id

I am not sure if this is the right way about going about this, and I am also wondering if there was a large number of players and if at every shot I had to iterate through each player to find the player who fired would this not be expensive on the server?

Thought of the answer just now, instead of running of running the entire calculation on the server I ran in it on the client instead and just created the projectiles on the server.

I think you need to better understand Replication, so I recommend taking a look at Billy Bramer’s Youtube videos on the Unreal channel on how it works.
The key is that all clients will always request the server to fire the weapon and the server would then spawn a projectile for the client that requested the firing and the projectile would then get replicated across all clients.
You should never need to use Player Indexes at any point. Every client is responsible for capturing the input key, sending a request to the server and the server should take care of the rest (regardless of who sent the weapon firing request).