DateTime object not replicating from server GameState to client GameState

My GameState is configured so the instance on the server continually updates a game clock DateTime object. Although the clock ticking is working perfectly on the server it is not replicating the updated DateTime object to the client. I don’t know if this is because I am reassigning the variable to a new object instance which may be breaking replication?

Here’s my GameState.

Here’s my UMG widget that is using the Game State replicated date time object. The result of calling GetHourMinutes is “0” which is the default value in the above Make Timespan. I launched PIE using the dedicated server option so the screenshot below is of a client connection.

93379-screenshot_060516_122214_am.jpg

When I run PIE without dedicated server so I play the game as client and server the result of the print string is below.

Here’s my GameState game clock variable.

93412-screenshot_060516_125912_am.jpg

This is the GetClockMinutes function in the GameState.

Hey there Elite,

I think your on the right track, because of the using “make timespan” and your not carrying all the values across from the “old” variable.

But instead of doing it that way, why not use the node “Set Member of XXXX”. Then you can wire in the variable you are using, and set the seconds value, with everything else being maintained as is, instead of creating a new TimeSpan object.

Here’s a link to my blog, where I describe it.

/b2evo/index.php/iwue4dev/

Hope this helps,

Inc.

Can you show GetClockMinutes

Also, why not un-replicate the time variable (seems uneccesary from what you’ve shown) and directly grab it from the gamestate and update your clock widget that way? Worked fine when I just tried it

I’m not seeing the "Set member … " node(s). Do I need to create a custom structure and use that instead of the built in DateTime structure?

Ok, I just changed the BP to this and it still does not work :(.

The updated DateTime object does not seem to replicate.

93412-screenshot_060516_125912_am.jpg

Sorry for the triple posting.

For completeness, here’s the GetClockMinutes method in the GameState object.

Thanks for your time in helping me figure this out. See my comments on the below answer ( I posted more blueprint pictures).

Also, my GameClockHud widget is already doing what you recommended.

(See my above question or click the link below)

I just saw that as well, that the node is not present for the TimeSpan, and was thinking about it. You have the Add Node for the variable, hence the Make TimeSpan is not what is really being replicated. As the Make TimepSpan’s

I know I hate DateTime and TimeSpan, I ended up writing my own nodes in a C++ library, and just drive everything off UTC.

Your original code, should actually be working, unless the Set node in a blueprint, is creating a new variable, logically it shouldn’t be, but what goes on under the covers…

Dang, not sure how to put together a test, to try to determine this.

With my knowledge of OOP, if you reassign a brand new object to an existing variable (in my case I am), then the new object has a different memory address pointer. This means any code that was referencing the original object address location will no longer receive the updated object.

Now, that is my knowledge of OOP. My knowledge of how UE4 replication works, well, I have none :). I don’t know if UE4 is smart enough to see that “oh this variable is now pointing to a completely different object, let me replicate that”.

Darn, I was really hoping to avoid creating a custom date time structure… I guess I can create a custom one and see if I can get it to work. Will post back here shortly.

Would you store the game clock in GameMode and client requests to GameState on the server would go to GameMode to get the updated time?

GameState class is set to replicate by default. Wouldn’t that replicate all the properties of GameState or only the ones that are marked to replicate? In other words if the game state object is set to replicate wouldn’t it send the game clock data every tick anyways.

Elite,

But your also fighting something else, or rather we both are. Yes, there are the mechanics of OOP,

But this is Blueprints, which are run by a VM, like any other P-Code language if you will. So what is Blueprints doing under the covers…

One would hope, that it’s not allocating (with the resultant deallocation, for the old object), merely because the variable’s value has changed, that’s what variables do for gosh sakes, they change! lmao

I believe I found [another] bug in the UE4 editor. I created a custom blueprint structure called DateTime with the same exact structure values as the native UE4/C++ one. Now my project crashes when ever I try to do anything with it or rename it lol.

There’s got to be an explanation why this DateTime is not replicating… Should I file a bug report? I don’t know if the UE4 development staff is active on this answers site.

oh good grief @ project crashing

But Yeah, I preface all C++ Structures with IWS ( Structure), as well as functions with IWxxxxx (where XXXX is the subsystem, like Mat for Materials, etc). Trying to keep away from all name collisions, etc.

I would file the bug report for the replication. In that your original code to me should be working, as your doing just an Add/Set sequence. Logically and mechanically you have no control over the Variable, whether it’s being created/destroyed or just merely updated (one can only hope it’s just being updated). But as you have no control, then Epic to me, is taking it upon themselves to ensure no matter how the variable is being altered, it’s still able to be replicated (assuming you have done everything needed to replicate a value, and I have no reason to think you haven’t).

There are representatives (, Stan, etc. and yes there’s more than just two! lol) here from UE4 to address this concern. Just be sure to put it under Bug Report/Crash etc, so it doesn’t get lost in the weeds.

Inc.

I just tried assigning the Minute structure pin to it’s own variable in GameState and then rewired my GetClockMinute function so it pulls the new GameClockMinute variable. The game clock UMG widget is now receiving the updated clock minute, so it’s definitely an issue with replicating the DateTime object :(… Or at least my design approach for replicating it.

93415-screenshot_060516_013925_am.jpg

File away Sir, File away… Let em know.

Inc.

After some more testing, it turns out that DateTime does not replicate properly… It seems to be a known bug.

For the meantime, here’s what I did as a workaround. Works great

Of course you wouldn’t want to call this every tick. I would suggest having the server/client sync up, and have the client independently change the clock, with checks from the server every so often. (And really you’d want to do it this way to save bandwidth usage even if datetime was replicating)

Thanks for your help in giving me reassurance that although I’m 1 week new to this I have a good understanding of multiplayer replication. I’m sure I will see you around!

Have a good one!

Do you have any good articles that outline this design approach you are recommending?

I’m not sure how I could achieve this without using event tick in the game state.