I’m developing a multiplayer shooter game and there’s a series of events i’m trying to get to replicate like picking up a weapon and reloading it. So far, the way i’ve done it is for every event there is an RPC called from client to server that executes another RPC that multicasts to every client. For example:
· Player presses input
· Weapon fires on server
· Server multicasts runs the fire function on the weapon for every client
However, instead what i get is that if a client presses the button calling the first RPC, the gun isn’t fired on none of the instances (it does fire properly when called in standalone), while if the server inputs to fire, the fire event happens correctly on server but does not get replicated to any of the other instances. If i understand correctly, that means that whenever any of my RPCs are called, for some reason UE doesn’t run them on any instance expect the one that called the RPC even though they’re set up to be replicated. This doesn’t happen with just fireing but also with every other event that is setup in the same way including opening crates, equipping weapons, using throwables, jumping, etc. Replication has always felt kinda confuse and difficult to research so i’d be very thankful if anyone could explain this to me…
First you need to ensure that the BP Weapon Base is Spawned by the Server only.
If you make a breakpoint (F9) on the node that spawns the BP you should see “Server” written on background of the BP when it hits the breakpoint"
Then you need to ensure that the Client that calls Fire_on_server owns the BP weapon Base it is calling from.
You should see an entry in the log saying “No owning connection for actor…” if this is the issue.
You can set the Owner while you spawn it by the Server. The owner should be the owner PlayerController or the Character that own the Weapon. When the owner Possess the Character it will then also own the Weapon.
Thank you so much! I went over the ownership thing again and saw that the part of the code that sets the player to own the weapon when picking it up was called standalone. I replaced the normal “SetOwner” function to this
and made the pickup function call Set Owner Server and set a one tick timer for itself when it sees the weapon is not owned by the player. The one tick timer thing is because when the player first calls the pickup function UE sees the player isn’t the owner, then ownership gets changed but unreal still had the function marked as non-owned and only resets by calling the function again. Kind of a headache and not the cleanest solution but it works perfectly and that’s what matters. Thanks.