Replicating a variable from Widget to Server

After a week I finally decided to give in and ask for an answer instead of googling my brains out. I’m quite a beginner and have worked on UE4 on and off for about a year or so.

I wanted to make a “board game” replica and I am having trouble of finding a solution or a workaround for my idea.

Basically what I want to do is I have money in the game in two variables cash and bank. On my widget I can transfer the money between them. Ex. I have 10 000 in bank, I type 500 into the text field on my widget and transfer it to cash. Which works fine but obviously not on server cause widget is not replicated by server.

So I’ve been looking for a way to replicate this variable from the widget to the server as well but with no luck. I end up either getting the same value for the client as the server has or just the default value from beginning. I hold these variables for the server in the player state, but I cannot seem to change this variable from widget on the client side.
Is there a way to get a variable from client as a server or am I trying to accomplish the impossible.

1 Like

I effin knew it, that as soon as I post here I will find a solution. I tried it before as well but apparently I must have missed something then. Anyway if somebody finds this and is having same issue then here is a solution.

The variable you’re trying to get from widget obviously has to be replicated and you have to cast it to your player controller which object is “get owning player”.
From your player controller you need to create a custom event which is replicated “run on server” which also has the input for the variable you’re trying to fetch.
Now from the widget BP where you did the cast, get the custom event you just created and attach the variable value to the input of your custom event.

And voila you can now set your variable inside the player controller via this custom event which can be therefore casted forward to the playerstate or where ever you need it.

1 Like