# Replication of a variable of the GameState

**URL:** <https://forums.unrealengine.com/t/replication-of-a-variable-of-the-gamestate/462246>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [March 9, 2020, 9:18am UTC](https://forums.unrealengine.com/t/replication-of-a-variable-of-the-gamestate/462246 "2020-03-09T09:18:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tuerkero](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@tuerkero](https://forums.unrealengine.com/u/tuerkero)\
**Post date:** [March 9, 2020, 9:18am UTC](https://forums.unrealengine.com/t/replication-of-a-variable-of-the-gamestate/462246/1 "2020-03-09T09:18:39Z")

</div>

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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/e/4/3e4bc217b4b96aff1749c05ee42ed21beca2b479.png)

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

![297518-replicated2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/6/f/c6f228dde74ef78a1b5eb0d5ac7c25b3184c6684.png)

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

![297520-replicated4.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/8/f/d8f082f34b2e16d26247e68033796a598bb2be15.png)

 ![297519-replicated3.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/f/2/cf2c03909dea665664bc33e5a71b7f2c87bccdc0.png)

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

What is wrong?

---

<div class="post-metadata">

**Author:** ![Arman](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/arman/32/728343_2.png) [@Arman](https://forums.unrealengine.com/u/Arman)\
**Post date:** [March 9, 2020, 9:33am UTC](https://forums.unrealengine.com/t/replication-of-a-variable-of-the-gamestate/462246/2 "2020-03-09T09:33:53Z")

</div>

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](http://cedric-neukirchen.net/Downloads/Compendium/UE4_Network_Compendium_by_Cedric_eXi_Neukirchen.pdf)

---

<div class="post-metadata">

**Author:** ![tuerkero](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@tuerkero](https://forums.unrealengine.com/u/tuerkero)\
**Post date:** [March 9, 2020, 10:06am UTC](https://forums.unrealengine.com/t/replication-of-a-variable-of-the-gamestate/462246/3 "2020-03-09T10:06:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TheKaosSpectrum](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TheKaosSpectrum](https://forums.unrealengine.com/u/TheKaosSpectrum)\
**Post date:** [March 9, 2020, 1:36pm UTC](https://forums.unrealengine.com/t/replication-of-a-variable-of-the-gamestate/462246/4 "2020-03-09T13:36:52Z")

</div>

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](http://interkaos.com/grabs/UE4Editor_noJgR1h2vm.png)

Inside your controller:

[http://interkaos.com/grabs/UE4Editor\_SVGGbb8Dlh.png](http://interkaos.com/grabs/UE4Editor_SVGGbb8Dlh.png)

Inside your GameState

[http://interkaos.com/grabs/UE4Editor\_xNPJlxHvot.png](http://interkaos.com/grabs/UE4Editor_xNPJlxHvot.png)

---

<div class="post-metadata">

**Author:** ![tuerkero](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@tuerkero](https://forums.unrealengine.com/u/tuerkero)\
**Post date:** [March 9, 2020, 2:24pm UTC](https://forums.unrealengine.com/t/replication-of-a-variable-of-the-gamestate/462246/5 "2020-03-09T14:24:34Z")

</div>

Thanks for your advices.

Now, it works.

This is the new code for the widget (My PlayerController is BP\_PC):

 ![297541-replicated6.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/f/8/6f89039561b55b247aa621c381be1c63bbd44f55.png)

And the code of the player controller:

 ![297542-replicated5.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/9/4/594022946069c440234b3227ca56605904ef4dc2.png)

GameState is empty.

---

<div class="post-metadata">

**Author:** ![Qlimax87](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Qlimax87](https://forums.unrealengine.com/u/Qlimax87)\
**Post date:** [November 19, 2022, 4:05am UTC](https://forums.unrealengine.com/t/replication-of-a-variable-of-the-gamestate/462246/6 "2022-11-19T04:05:45Z")

</div>

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
