Persistence
Persistence is a quality that allows us to perform actions in a simulation and if a user connects later, the actions that have been executed are restored and thus find the simulation in the same state as in the rest of the clients.
Important
VIROO provides tools to achieve this goal. The proper restoration of the simulation lies in the hands of the person who creates the content.
Persist Type
There are three types of persistence:
| Types of persistence | |
|---|---|
| Field | Description |
| None | No persistence will be saved. |
| Last | Only the last status or action will be saved and this is what will be restored. |
| All | All actions or all state changes of the object will be saved, depending on the case, and will be restored at once in the order in which they have been performed. |
Actions
By default, actions have the ability to have persistence. Just set the PersistType field to Last or All.
Besides restoring the Action itself, if it has behaviors assigned in the OnActionStarted and OnActionFinished callbacks, these will also be executed when restoring, this should be taken in consideration when using this callbacks.
If the persistence is set to Last, the callbacks will only be called once. If persistence is set to All, they will be called as many times as the action has been executed.

UnityEventAction has two different callbacks, one for the normal execution and another one for when its state is being restored, this way, it can be decided what to do in each case. The OnRestoreStateEvent is called on users joining a session in which this action has already been executed.

UnityEventNonBroadcastAction does not have persistence since its actions are executed only locally.
XR Interaction Toolkit Interactions
By default all the interactions that are triggered from Unity's interaction system, XR Interaction Toolkit, are only executed locally, to transmit them over the network you need to add the corresponding VIROO component necessary for this purpose.
For example, the XRSimpleInteractable needs the VirooXRSimpleInteractable. If this component is used to send the events over the network, these will have persistence as well as the Actions.
If VIROO Actions are called from these events they are already synchronized over the network and, if the Execute method of the Action is called, the interaction will be called twice by both the Interaction and the Action, which can produce undesired behaviors. In the case that the interaction is sent over the network, the LocalExecute method of the action should be called.

Important
If the Execute method of an Action is called, the SendNetworkEvents option of the associated VIROO component must be deactivated. In this case, the Action will persist but the interaction will not, they would be sent twice and Execute methods would be called twice for remote users.
