Networking RPC (client -> server) & Ownership

I have recently switched to the Unreal Engine and I am having a hard time understanding how to execute RPCs from the client to the server. I know that for security reasons a client can only send an RPC from actors it owns.

But I am unclear about how I would achieve that. I have prepared a small example to illustrate my problem. When the server presses the lower button, the client receiver should turns green and vice versa.

However, with the way it is implemented at the moment, when I press the lower button on the server it turns the servers receive button green and when I press the lower button on the client nothing happens.

I watched all networking related tutorials (and read a lot of related answers here) but I think I am missing something important…

How would I get this example to work?
Thank you for your help!

“Client” will execute that RPC on the owning client. So the server probably owns these objects because this is a server authoritative networking scheme, and so if the Server presses the button and sends an RPC to the owning Client, it effectively sends it to itself.

If you want client(s) to see the event when the server executes it, then you should use a Net Multicast RPC. Why it’s not working when the client presses the button I’m not sure.

In the scenario of if you want everyone to see the Receive here turn green, this is what I would have done:
There’s a RepWNotify bool on the receive object. the OnRep function changes the color based on true or false. When a client presses the button, it sends an RPC with a value of true to the server. The server then sets the RepWNotify bool on its end, and everyone gets notified.

Thanks for the quick answer! Switching to Multicast doesn’t work in this scenario and RpWNotify will not give me the desired effect either. Player A should do something only Player B can see and vice versa. Multicast and RepNotify would also update the senders receiver. Right?

Yeah, notify would in blueprints I believe. The “Owner” problem still exists for you though, and I think what you may need to do is have clients ignore the messages that aren’t intended for them. I don’t really know of a way to send a message to a specific connected player only. If you only have 2 players, then maybe you can just make the owner of the receiver the client, and what you have would then work. To make the owner the client you might have to dabble in the C++, as SetOwner is not BP accessible.

It is a problem with the ownership, I finally got it to work by moving everything to the player controller since every player owns a specific player controller. This is not a good solution though since the player controller is now very bloated.

I know how to change the ownership of my blueprints, but how do I make them owned by the client?

I don’t know if there’s a way to control ownership in blueprint. You’d have to do it on the C++ side, and even then it’s not entirely clear to me how ownership works. If you are asking how to make the owner of the blueprint be the client on each machine, this simply won’t work because then how does the server know who owns what. You’ll have to do something like I think you are already doing - have the server communicate to the player controller and that in turn will change the object. I think I could help you better if you can tell me the long term goal of this. What are you trying to accomplish?

The basic idea is: 3 cards are spawned for each player, clicking a card deals some damage to the other player. It would make sense to have the cards owned by the machine they are spawned on, so that I could have the networking functionality on the card blueprint itself. But right now they all seem owned by the server.

Someone had a similar problem [here][1]

It seems there is no way arround having the “Run On Server” RPC on the player controller (or another blueprint owned by the client) and calling it with “get player Controller → RPC” I couldn’t find a way to change the ownership of a blueprint to be owned by the client (if you know a way, or know what makes the player controller so special, I posted this question [here][2]).

The reason why this solution is not great is that my blueprint is now dependent on the player controller, which will make it more difficult to reuse.

This is the setup that worked for me in the end:

This is on the Player Controller

39105-screenshot+(7).png

And the result