I have been trying to figure out a replication problem. I am making an FPS and I want to drop a weapon and then store the stats into the dropped weapon on begin play. This is what it looks like.
Drop: (Spawns the actor of the equipped gun)
Store Values: (This stores the values from my weapon base blueprint into the weapon being dropped)
Overlap Print: (This prints the gun stats when my first person character overlaps)
Say that the server shoots all the ammo in the magazine and then drops the weapon. The client can pick up the weapon and all the stats are perfectly fine:
Server Shoot (Server shoots all ammo in mag)
Client Pick Up
But now, let say that the client shoots all the ammo in the magazine and then drops the weapon. The server picks up a new gun and can't seem to read the variables that the client sets.
Client Shoot (Client shoots all ammo in mag)
Server Pick Up
Here are the overlap print statements:
The Server Drops the Weapon and the Server Overlaps:
The Server Drops the Weapon and the Client Overlaps:
The Client Drops the Weapon and the Client Overlaps:
The Client Drops the Weapon and the Server Overlaps: NOTE: Issue
I know that this is a lot to look through, but any help would be greatly appreciated. Thank you!
If you need anymore information to assist with the problem let me know!
On client drop you need to RPC the server the changes to the weapon. Otherwise ALL changes have to happen on the server in the first place.
Server spawns weapon, Actor replicates. Client overlaps to pick up, RPC’s server. Server checks overlap and attaches to client character.
Character fires, RPC’s server to shoot. Server shoots and deducts ammo, rep_notifies the ammo count back to client.
Client drops weapon, RPC’s server to drop. Server detaches, drops.
Sorry I am still learning replication. So when you say that I need to RPC the server changes to the weapon, would that require a run on server inside the weapon blueprint?
Yes, but from Character or Controller.
Input pressed → switch has authority: remote → RPC (Run on Server)
Server (RPC): switch has authority: Auth → Make change/Fire Weapon/etc etc
So does this only work on input from a character/controller? Not a begin play?
You can do begin play → switch has auth → whatever.
Yet this action should be run on the server at creation. Client shouldn’t be doing anything “begin play” on replicated actors.
So if the weapon actor itself is spawning on server, will the begin play trigger on server?
yup, but you need to ensure it only executes on the server.
Ok! I will try to mess with it a bit. Thanks.
If your begin play changes aren’t applying to the client end, then you may want to disable replication by default and enable after begin play changes apply.
This is the only hitch I can recall happening. Other work around is to rep on default and multicast or rep_notify the begin play changes as needed. Downside here is multiple uses of the network and delays on the client with changes.
Can you explain how I would do that? Would I just uncheck replicates in the actor settings?
I am not sure if the problem is the begin play. When I try to store the clients weapon variables into the weapon pickup they do not show to the server. Basically, I cast to my FPS character then I cast to the weapon and then grab each variable (fire rate, ammo, etc.) and store them into the weapon pickup on begin play. I just cant seem to figure out the client side.
There’s 2 copies of the actor. One is on the server (Authoritative) and one on your client sim (Simulated).
When your client changes values on its copy it isn’t changing them on the server. It’s only changing local data.
If the client makes direct changes it has to UPDATE the server via either REP_Notify or RPC (run on server).
The Best Approach as noted previously is to RPC the server to make the change and have it Replicate those changes to clients.
My personal approach to weapon configs is to use a data table to set the variables at creation.
Server Spawns it. In construction it reads the table, and sets values in a struct.
When an action occurs that can change the values it’s done on the server not the client.
Just checking in… You figure it out?
Just checked in as I am learning MP too and thanks Broski for your support, it’s clear and nice written <3
Thanks for checking! I’m still struggling. I’m just trying to troubleshoot with print strings. I have the server spawning the weapon and I have the client variables updating with a run on server but it is still the same. I thought of trying a data table like you said but I haven’t found any videos explaining how to do that with weapon dropping.
I’m slammed with work today, but I’ll whip up a demo this weekend.
Wow that would be amazing! Thank you!