Save and Restore Actors replicated members

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?

Ok I have found enough so that I can build the thing that I want. For anyone who is also interested:

You can interate over all properties with TFieldIterator (http://api.unrealengine.com/INT/API/Runtime/CoreUObject/UObject/TFieldIterator/index.html).

The Uproperty Objects provides many introspection functions which can be found here: http://api.unrealengine.com/INT/API/Runtime/CoreUObject/UObject/UProperty/index.html

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”.

To write to and read from memory, you can use a subclass of FMemoryArchive (FMemoryArchive | Unreal Engine Documentation).