Why can't Widget of client call RPC of server?

Inside a widget(a menu) which is owned by a client, I’m using the following code to ask server to print a string. It failed.

The result on my screen is still saying this is printed out by ‘Client 1’ instead of server.
image

Then, I tried to use its PlayerController to call server with the code below.

image

This time, it works. The result says this is printed out by ‘Server’ instead of ‘Client 1’.
image

Does anybody know why can’t call server inside widget blueprint ?

Player controller blueprint has a copy on client and server side. So server copy can tell client copy to do something and client copy can ask server copy to do something.
Widget blueprint exists only on the client side, so its “Server” events cannot be really executed on the server side.

1 Like

That’s not entirely true. Take for example a listen-server player, he has his widgets on the server.

The thing is that actors that are not replicated can’t fire RPCs. UUserWidgets are UObjects and not AActors, and they are not even replicated. For UObjects to replicate and be able to fire RPCs extra steps must be taken.

Anyways, back to the example above, to be able to fire server/client RPCs you must do that in client-owned actors, which are typically PlayerController/PlayerState and Pawn in case it’s possessed/owned by a PlayerController.

2 Likes