I am currently implementing a lag compensation algorithm. I am currently trying to figure out, if there is an effective way to save the state of all replicated meber variables and later restore them using that state.
The Unreal Engine Replay System (DemoNetDriver), suggests that this is possible. However, I the replay system does not suit my needs. I am currently trying to figure out how to solve my problem by reading its code, but had no success so far.
I could do it manually, but then I can’t really use the UE4 replicated variables anymore / have to maintain redundancies.
Does anybody know an effective way to use replicated variables to save state?
To check whether the property is replicated you can use “UProperty::HasAllPropertyFlags” with the parameter “CPF_Net” or something similar. It is possible to get and set the values with the help of the UProperty object. You probably need to cast the property first, e.g. UNumericProperty to access the values. Or use the TFieldIterator with that type, to skip the unneeded properties and don’t need to manually cast to that type.
When you can the value you might want to call the OnRep function. You can do this with find an example to do this in the “DataReplication.cpp” file. Search for “RepNotifyFunc”.