Issue: In my project, server RPCs initiated by a client on server-owned actors (such as weapons) are being dropped (see image under). This setup is critical, as the weapons are created on the server, attached to clients, but remain server-owned. Since many multiplayer games also use server-owned weapon actors, I’m looking for a solution that allows client-initiated server RPCs to work on server-owned actors without them being dropped (there must be a way of doing that).
Question: How can I reliably send server RPCs from clients on server-owned actors (like weapons attached to players) while maintaining the current architecture? What strategies or best practices exist for handling this in Unreal Engine multiplayer games?
All you need is to make the client the owner of his weapon on the server (using SetOwner function).
Initially, the client only owns its player controller. Then the controller becomes the owner of the Pawn.
Initially, the client can only send RPCs to the server from these actors.
To allow the client to send RPCs to the server via a weapon - make the client the owner of the weapon on the server.
I think I’ll change my way of doing things and Spawn the weapon in the Player Controller, so they are accessible from the Server and client who spawned it ONLY while still remaining server owned…
An actor cannot have two owners. Owner is a replicated variable, and it can only have one value, and it is thanks to it that the engine “understands” who can send RPCs and who cannot.
It doesn’t matter where you write the weapon spawning logic. The main thing is that it is called on the server, and then the right client becomes the owner of this weapon.
So Weapon Setup should happen on the Server, then at the end of the setup, I should be setting the owner to the according player controller? Is this correct?
PC should be the Player Controller that is going with the Player Character we are in… (I’m not sure if it actually works since it’s a server only function…)
It’s fine if it’s few frame late but it should AT LEAST trigger…
I’ve just realized that there’s a warning in the logs that is pretty interesting about the problem:
LogNet: Warning: UNetDriver::ProcessRemoteFunction: No owning connection for actor CustomWeapon_1. Function ServerAddNiagaraComponent will not be processed
This means that when you call SetOwner, the new owner is set to a different controller than the one you then try to call the server event from.
Can you add GetOwner name to the output log in the weapon tick function if Owner or other message if owner in not valid?
Before doing SetOwner(), GetOwner is nullptr, after setting it, it’s PlayerController_1.
You just said that the new owner is set to a different controller than before, but is the server PlayerController and the client PlayerController the same? (Is getting the PC on the server the problem?)