How set correctly a variable in a PlayerState from a GameMode (networking environment)?

Greetings!

I would like set a variable in every PlayerState from GameMode. How should I do that (with a example, please) ?

I tried many things: “Blueprint Interface”, castings, RepNotify and RPC. Only the server could answer, so I certainly missed a thing.

I know that GameMode is only server-side, but cannot I passing any informations directly?

Thanks a lot!
Best regards.

You need to create an event and set it to “Replicate on server” and “Reliable” (often recommended for variables). And on this event, you update the variables you want to update. But you must also set the variables themselves to “Replicate” and then hopefully it should work for you.

Thanks ! I will looking at that and I’ll be back with the result. Thanks again! :slight_smile:

I’m back with the result (click on the pictures to enlarge), if I understood you:

  1. Image hébergée par servimg.com

  2. Image hébergée par servimg.com

  3. Image hébergée par servimg.com

  4. Image hébergée par servimg.com

Can you see that I don’t understand? :slight_smile:

Thanks a lot!
Best regards.

On player state you should have something like this:

In my case it’s called from the player controller but should work from game mode too.
Also in your screenshots you have an increment node which looks wrong.

Thanks for your answer Getty_g! :slight_smile:

My increment is useless, you’re right! Also, I tested my “cast to MyPlayerState” and it failed.
Then, I wanted gather PlayerStates from GameMode (by Game State → Player Array) and it failed too.
So, I suppose that GameMode begins before the apparition of the PlayerStates. I will explore this more in depth.
I’ll be back.

Thanks a lot!

You’re only printing the boolean in event begin play? Try printing it in event tick to see if it’s changing. It is very possible the player state begin play is initiated before the game mode is able to do the requests.