My Question: How can I get the Playerstate from the Server on the Server and on the Client the Client:) I understand that I call “Get Player Character” with index 0. But how can I get always the correct index? Is this the problem?
To get the correct player state index on the client, you need to use the GetPlayerState function with the index of the player you want to get the state for. This function returns the player state at the given index in the game state’s PlayerArray.
To get the correct player state index on the server, you can use the GetPlayerStatefromUniqueNetId function with the unique network ID of the player you want to get the state for. This function returns the player state that matches the passed in online id, or null for an invalid one.
It’s important to note that the index of the player state will be the same across different clients and servers as long as no new players join or leave, but it will not be the same across different clients and servers.
This is surprising, GetPlayerCharacter(0) on client side is actually supposed to return the local player’s character (client). If not, that’s news to me.
Since you are in a widget, use GetOwningPlayer to get the player controller associated with the widget, and get player state from the controller.
But as mentioned, I suspect you might get the same result, as the issue would be elsewhere.