[Documentation] Wrong Information, RPC calls

Hey,

I’m just about multiplayer and came across this tutorial in the docs:

RPC Doc

The Section “Run On Owning Client” messes things up. A TriggerBox is placed in the level and referenced in the level Blueprint. There the two RunOnOwningClient-RPCs are created (Add Item, Remove Item). These are getting called from the server (SwitchHasAuthority). The Error here is that these events will never be executed on the owning client, cause they are within the LevelBlueprint which is owned by NONE. As the video in the doc clearly shows (the moment a client walks into the TriggerBox), the SERVER is doing the PrintString =“Item added”, NOT the client. The inventory gets updated correctly in this case, but not cause of the RunOnOwningClient-RPC, instead the replicated variable does the job.

The section should explain RunOnOwningClient, but the code will NEVER run on the OwningClient, cause there is NONE. And if the object has no owner, the Server will execute it.

Cheers

It’s not about the owner of the trigger box. It’s about the owner of the character the trigger box overlaps with, I guess. (I just headed into multiplayer stuff on my own a few weeks ago, but I think I can explain that to you, because you have to wrap your head around ownership in some way - so feel free to correct me)

Quote of the documentation:
“Here we are stating that when overlapping the trigger, if the overlap occurs on the server, run the Add Item event on the server and replicate it to the owning client (which is the character that overlaps the trigger). The “it” is the script that is called when Add Item is fired off and is only executed on the server but replicated to the client. When the character leaves the trigger box, again determined by the server, run the Remove Item event on the server and replicate it to the owning client.”

The trigger box is part of the Level and therefore owned by the server. But this script is checking who is the owner of the Character the trigger box overlapped with and that is the client itself which is fine. So when the “RunOnOwningClient”-RPC is run, only the client with the character will get the replicated information, so not everyone “has the Item”, but only the character which overlapped with the trigger box.

In the video they fire multiple checks of the inventory, which is just a keypress on P (see Point 4.). The client who owns the character the trigger box overlapped with does indeed have something in it’s inventory (because the “RunOnOwningClient” told him so). The clients who did not overlap are not part of that RPC so their inventory remains empty.

Hey Rumbleball & VizualTek,

So this tutorial is working as intended. I think you may be getting confused with the fact that the first HasItem print comes from the Server. But in that case the Server is the owning client, because the server is the one who entered the trigger box.

If you notice later in that same video, Client 2 enters the trigger box and Client 2: Has Item is printed to the screen, indicating that this is working as intended.

We are not looking for the owner of the level blueprint in this case. We’re looking at the owner of the character, which would be whichever client that character belongs to. Whichever client overlaps the trigger will be the client that the AddItem event is called on.

Let me know if you have further questions.

Thanks for your replys.

“We are not looking for the owner of the level blueprint in this case. We’re looking at the owner of the character, which would be whichever client that character belongs to. Whichever client overlaps the trigger will be the client that the AddItem event is called on.”

That is exactly the issue, cause it is not that way. You are not looking for the owner of the character. The OwningClient-RPC function got the parameter “Character” added to it, how should the OwningClient-RPC function know which of the parameter (if there would be multiple) to check for the owner? The OwningClient-RPC function can only check the calling instance (which is the LevelBlueprint on the server). The LevelBlueprint belongs to NONE and thus the OwningClient-RPC is executed on the Server as statet in Network Compendium Page 60 which is just a copy of the original Unreal table.

Let me try that the long way.
The Character is moved by the client and the movement is replicated to the server instance of the client character via the movement component.

The server instance of the client character now triggers the box, which leads to execution of the BeginOverlap with OtherActor being the server instance of the client character.

Cause we are on the Server, we will get successfully passt the SwitchHasAuthority.

Now on the Server, we call AddItem-OwningClient-RPC which will check the calling instance (the LevelBlueprint) for the owner. Again, the “Character” variable is just a parameter added to the AddItem-OwningClient-RPC and can not be checked by the RPC function itself. The “Character” variable is not checked afterwards (by the script) either.

Cause of the above reason AddItem-OwningClient-RPC will execute on the server, which is shown by the “Server: Item Added” PrintString in the video at time 0:38.

Still on the server, the “Character”-Parameter of the AddItem-OwningClient-RPC, which is the server instance of the client character, is cast to the ThirdPersonCharacter.

After the cast, the “Inventory” variable is set in the server instance of the client character. The “Inventory” variable is then replicated to all client instances of that character.

For sure Client2 got the item now, but not because the OwningClient-RPG function was executed on the client. Its because the Inventory variable was replicated.

You would get the same behaviour when simply cutting the OwningClient-RPC from the execution chain. Just Overlap->SwitchHasAuthority->CastToFirstPersonCharacter->SetInventoryVariable will result in the same result.

Check this yourself. Build the example as in the doc and remove the replication of the Inventory variable. You will see that it will not work anymore, cause the OwningClient-RPC is NOT executed on the client!

cheers

Thanks for your replays, my comment is to long so I needed to post it as answer. Please check that.

cheers

Hey Sean Flint,

I know you got much to do as support, but it is really unapreaciated to ask for further questions but don’t get to it and just mark the question as resolved. I took the time to make an indepth comment on what is happening. I would really appreciate if you or someone else will read over that one. If there are errors in my explanation, it would be nice to point them out, as it is important for understanding Unreals replication.

Thanks.

Hey Rumbleball,

When you mark a topic as resolved (which is done automatically when a comment is posted), it moves it out of our support queue, which is why you have not received a response. I’ve read over your response, and from what I see this doesn’t seem like a bug. We do not guarantee support for development questions. If you believe that what you’re experiencing is a bug, please create a simplified test project that showcases the issue and provide me with a download link through Dropbox or Google Drive. I’ll be glad to take a look.

Thanks

Ok, thanks for your reply Sean Flint.

It’s not a bug im refering to, neither a development question.

That part of the documentation should provide a working example for a OwningClientRPC call. But the example does not even make use of the OwningClientRPC. And YES, the example is working, but NOT because of the OwningClientRPC call, which this part of the docs should explain.

regards.