Can't get gamestate on client?

Hello,

I have a very strange issue that I have no idea how to fix.

So in my gamemode i use “OnPostLogin” event. I then retrieve the connected client, cast to the proper controller class and then I fire an “On owning client” event that adds a widget to this client. Now from within the widget I use “get game state” to retrieve the list of “playerstate” array. For some reason the widget can’t access the game state, it always returns 0. Althoug the widgets are added to the client as they should, basically everything works perfect, except that I can’t retrieve the game state on the client, server works fine.

The strange thing is that when I call this “on owning client” function from within the player controller itself, it works just fine. But when I call it from the gamemode using the connected controller ref it doesn’t work, although it kind of DOES work as it adds the widget and everything just fine, except that the in this “on owning client” I can’t access the gamestate.

Anyone have any clue what this strange behavior is?

This is the post login event inside gamemode

this is the on owning client event inside player controller

The widget gets added to client’s screen just fine. But inside the widget I can’t access the game state. When I call the OC_OpenConquestScreen event from within the controller it works but not from within the gamemode.

This is inside the widget:

On the client it always returns not valid for the gamestate.

1 Like

Nevermind I found the problem. Appearantly gamestate takes a while to initialize, using a delay works. Although I really don’t like using delays as they are unpredictable and if they are too short it can still not load. Anyone know a better solution?

2 Likes

where did you add the delay?

1 Like

Instead of triggering an RPC from PostLogin, spawn your widget from GameState’s BeginPlay on client-side. This way the game state is guaranteed to exist when widget is constructed.
In short:
YourGameState : BeginPlay → if not dedicated server → create widget

That was it. Thank you! And did you manage to solve it without the delay ?