Replication of a variable of the GameState

Hi!

I am trying to do something simple. I want to change the value of a variable “MyNumber” located in my GameState (BP_GS) from the client.

The variable “MyNumber” is in the GameState an it is replicated:

297516-replicated1.png

The custom event “ChangeValue” is located in my GameState (BP_GS) and it has “Run on Server” property.

297518-replicated2.png

The value can be changed and printed using a widget attached to the main map:

297520-replicated4.png

The problem is that the variable is changed when I am on the server, but not in the client.

What is wrong?

Hi.
GameState doesn’t belong to the client.
you can’t ServerRPC from a proxy when it doesn’t owned by client connection.
before starting with networking with unreal , i totally recommend you, read this amazing doc first. it’s about how networking works in ue4. cheers!
link text

1 Like

Thanks a lot for your answer. According to the Network Compendium:

“The GameState is replicated to all Clients. So everyone can access it”.

It is clear for me that clients can access GameState data, but, from your answer, I guess that they cannot modify it.

I would be very grateful if you, or somebody, can give me a clue on how to proceed.

Widgets can not send RPC requests. RPC to the server or from Server to the Client must go through a owning connection. IE. PlayerController, Controlled Pawn(Character) or something else OWNED by the player (via SetOwner). For the above to work, you should have a function on your PlayerController called ServerChangeGameStateValue which your widget should call, to change the variable on the GameState. Hope this helps.

Inside your widget:

http://interkaos.com/grabs/UE4Editor_noJgR1h2vm.png

Inside your controller:

http://interkaos.com/grabs/UE4Editor_SVGGbb8Dlh.png

Inside your GameState

http://interkaos.com/grabs/UE4Editor_xNPJlxHvot.png

Thanks for your advices.

Now, it works.

This is the new code for the widget (My PlayerController is BP_PC):

And the code of the player controller:

GameState is empty.

TY TY For making this post. This got me back on track and I now have a working GS Array. I guess I had to picture it as a big hierarchy. Peon cant talk to the king directly