State Accessors.








#include "NetworkedSimulationModel.h"


template<typename TState>
const TState * GetPendingStateRead() const


State Accessors. This allows game code to read or conditionally write to the pending frame values. This mirrors what TNetSimStateAccessor do, but is callable directly on the NetworkedSimulationModel. Accessor conditionally gives access to the current (pending) Sync/Aux state to outside code. Reads are always allowed, Writes are conditional and null will sometimes be returned!

Authority can always write to the pending frame. Non authority requires the netsim to be currently processing an ::SimulationTick. If you aren't inside an ::SimulationTick call, it is really not safe to predict state changes. It is safest and simplest to just not predict these changes.

Explanation: During the scope of an ::SimulationTick call, we know exactly 'when' we are relative to what the server is processing. If the predicting client wants to predict a change to sync/aux state during an update, the server will do it at the exact same time (assuming not a mis prediction). When a state change happens "out of band" (outside an ::SimulationTick call) - we really have no way to correlate when the server will do it. While its tempting to think "we will get a correction anyways, might as well guess at it and maybe get a smaller correction" - but this opens us up to other problems. The server may actually not change the state at all and you may not get an update that corrects you. You could add a timeout and track the state change somewhere but that really complicates things and could leave you open to "double" problems: if the state change is additive, you may stack the authority change on top of the local predicted change, or you may roll back the predicted change to then later receive the authority change.

What still may make sense to do is allow the "In Update" bool to be temporarily disabled if we enter code that we know is not rollback friendly.

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey