Help understand RPCs (client to server calls)

I’m trying to have my client’s weapon call a server function on overlap, but the server function is never called (in-spite of being the owning client).

According to documentation (A Crash Course in Blueprint Replication - Unreal Engine):

"Server RPCs can only be called by a client who owns the actor executing the event graph."

Shouldn’t the following work?

Thanks in advance

First of, you forget to check if actor actually has authority inside your server RPC :slight_smile:

And yeah, it should work like that, not sure what’s the case…

I’ve got it up set like that(in example of weapon firing):
Weapon::Fire()
Weapon::ServerFire()

Weapon::Fire() checks for role, and if it’s not ROLE_Authority, then it calls ServerFire, which is reliable server function. If it’s authority - it processes firing.

Hope this helps you some way.

Edit:

Forgot to mention that ServerFire simply calls Fire.

Thanks for the suggestion BiggestSmile, I do check for authority in the real code (the above is a contrived example of the issue).

I managed to get it to work with what feels like a crummy workaround: I moved the server function to the Character and the weapon calls that one when it does not have authority (which in turn calls the weapon function to apply the changes :\ ).

I doubt this is the proper solution, and I’m far from understanding why this is happening

I’d like to know what the condition of being “owned by the calling client” is. I’m in the same situation as Grogger. I have an actor with the RPC functions set up, but the server functions never are called. I placed the actor in the world through the editor (did not spawn it through code), which explains why it’s not owned by the client, but I don’t know how to make the client own it in the first place.

Executes on owning client is exactly what it sounds like.

It’s being executed only on client that requested this call, server will know nothing about it. In case of condition, function will be called only on the proxy that client, which requested the call, owns. If i recall correctly, only the AuthorityProxy will work with such a condition.

Try displaying actor’s role and see how different conditions affect results.

displayall class property

displayall MyGameCharacter Role should work just fine.

The Client calls RPC, but it runs on server. So anything later than red node TestServer will be executed ONLY on Server. In Epic’s tutorials all firing, damage and other changes executed on server. This functions change replicated variables. And clients “feel” the result. So, if you want fire weapon, just call it from any client with RPC. On Server run bullit movement and hit detection.
But health, bullit and other parameters are “Replicated”. So, changes on Server will be seen on clients.

Server - gameplay calculations, clients - input, HUD, graphics and calling. You can make calculations on clients too, but first need training like I wrote, to make it feel!

Thank you for the response MoD, though I think you may have misunderstood the issue: The problem is that the red TestServer node is never triggered on the server in my example (although from my understanding, it should be)

I’m in the same boat as you and James Ordner, I’ve got net-ready drivable vehicles that the player character can posses. Everything kinda works except the RPC calls from the vehicles dropped or spawned dynamically in the level.

At least now I know why, but now I need to understand how to change who the owner of a particular Actor is… can this even be done? I assume only the server can determine ownership.

Did you ever happen to find more information on this? I have a separate question exactly about this, here: Need clarification on Networking, Controllers, and Network Ownership - Multiplayer & Networking - Epic Developer Community Forums

Sort of, though I’m still wrestling with trying to get it to work. I’ve haven’t had much time for development the last 2 weeks but I’m going to be back on it this Sunday and onwards.

You can see the discussion I’ve been having on this particular topic here: https://answers.unrealengine.com/questions/92176/posses-a-pawn-as-a-client-on-dedicated-server.html

In the absence of an example project from Epic or some other third party I’ll probably do a write-up and example in the Wiki once I have it working.