Most likely it’s the way you are trying to reference the character class using
Get Player Character (index)
. This is used in Single Player / COOP.
This will work on the server but it only ever gets the first player to join. If using Listen Server setup, Player hosting as server, Then Player 0 is the Host and Server.
If the weapon is spawned by the server proxy character, or attached to the character you can do the following to get/set a reference to the owning character.
You’d run the following code off of begin play in the weapon class. Might need to use a delay node depending on your set up.
Another concerning section is the Get All Actors of Class
Loop for setting the weapon reference.
Get All Actors of Class (BP_WeaponBase_C)
will get a reference to every BP_WeaponBase_C actor in the simulation. Not just the one on the shooting character.
If you have 4 players and each has a weapon it will get those too.
Then there’s the loop → cast → set reference part.
Again, if there are 4 weapons in the game world you’re setting the current shooting characters weapon base ref 4 times each time you fire a single shot. You’re also not guaranteed to use your characters specific weapon. The last index is what you will be using. It’s what every player will be using.
Next, I’m seeing a lot of switch has authority
→ Multicasts
etc for doing a single shot. Not to mention you’re shooting from the server and replicating that down. Any player with a ping over 30ms is going to feel input lag. When a player presses Fire a shot mechanic should happen on the client immediately (fakey for responsiveness). Your approach adds full ping + server processing delays.
Player with a 100ms ping on a 30Hz server will have each shot fired delayed by 133.333ms minimum.
You should be setting a reference in an inventory as soon as the weapon is spawned for the player.
On Input Fire you should be checking that reference is valid and then call the Shoot functionality directly from that reference.
My setup is for dedicated server. It’s a Client-Fakey Server Auth model.
Client Fire Weapon
event determines firing mode in the weapon class.
The Mode calls the correct firing logic (semi-auto, burst, automatic)
The Firing Mode event (SemiAutoFiring) calls a function that executes the logic to fire a single shot on the client. Then calls Srv Fire Weapon. The server inturn takes the same exact course of action.
SRV SemiAutoFiring event is called which executes the Single_AuthoritativeFiring function. The Authoritative firing function itself calls the MC Single Shot Fired event so simulated proxies will execute a localized shot on each of the “other” clients.