Download

Player State replication not working

Hi !

I’m not sure to understand how the replication of the player state works. Well I was “understanding it” before I tried, be now after 5 hours of frustration I’m not so sure I understand!

I stored the player score in a custom player state. I’m then accessing all the player state from the game state ( “PlayerArray” ). Up to there everything works fine, but when I access my “ScoreData”, it’s always empty on the client side, but not on the server side.

So, this is how I initialize the ScoreData ( in the player state itself ) :

b07086bab594da2db5ae327183d3bdbfb79c39fd.png

39615bbbfcb838de64747212d770e9795e159305.png

Then if I try to access the ScoreData from the server it works. But not in the client. To test it, I added a print in the character ( not the controller ). So the character get its player state, and print the “display name” of the score data :

4b25d19ff190c2957b4744f106bf89aa8ce812ad.png

There’s the result :

Everything works fine on the server side… If I kill someone from the server, it’ll show up in the score on the server side. If I kill someone on the client side, It will show up in the server side score ( in the widget ).
But I can’t get the widget to show up on the client side, because the ScoreData is always null… To add the “kill and dead” numbers to the score when a character is killed, I access the player state ( using GetPlayerState on the PlayerCharacter ). The only difference is I’m on the server side, but it’s suppose to be replicated… ( And yes, the “ScoreData” is set to replicate :slight_smile: )

This was the part I thought was the most “weird”. But in fact the problem is when i’m trying to access the data from a widget on client side ( not from the character )

4e62f8b0a2b0fe083f0a3a12fd7be2e957be4daf.png

The “ScoreData” in the Player State is null after the cast… It’s the same behavior here, If I print when In the server it show two “ScoreData” “DisplayName”, but when I hit tab on the client side, it shows nothing ( the ScoreData is null )

Anyone know what I’m doing wrong ?

Thanks! :slight_smile:

Edit :

I forgot to say, I’m not using a dedicated server :slight_smile:

Hi!

I found that the problem is that I am trying to replicate a custom Blueprint Object class. I did this simple test :

a632e937b2bbd1fc4a17d2f68ada350fe2c74a13.png

When I print string the “Score Data”, it print two value on the server but two empty string on the client
And when I print the boolean “Test”, it correctly print “True”, that was set on the serveur, on both the server and the client…

So now I’m wondering if it is even possible to replicate my custom Blueprint Object class ?

Thanks!

Under the replication tab (should be located in the list of tabs on the right side) on your blueprint for your custom class, there should be a “Replicates” check box. Make sure that is checked.

Hi!
Thanks for the answer, but I already looked a thousand time!

Seems like there are no “Replication” tab :

0e89ba7424eedee3e2989f2dc7ec23ec8b1cc659.png

44b6ed2f691dd0a918c7e96f6364f9a294d786c1.jpeg

I did it entirely with a structure as it seems to be working. But I’m already starting to store other data ( for the tool bar now… ) and it is really frustrating to, not be able to encapsulate functions and variables in an object… The best I can do is put variables in a structure but it doesn’t looks really clean

Thanks :slight_smile:

You can’t replicate Objects :stuck_out_tongue: Actor is the first class that replicates.

You could replicate the Objects with C++ as Subobjects, but in Blueprints you can only replicate Actors and their Children.

Instead of an Objects, you could use a Component. They can replicate.

Oh… That’s not clear, I can set the object variables to “Replicate”… The option should be removed on the variables if the entire object can’t be replicated!
Well, at least I won’t make the mistake again :slight_smile:

Thanks!