// Persistence private void PersistenceTick(double deltaTime) { // Wait until we're in sync with the server if (_connectionState != ConnectionState.Ready) { return; } _deltaTime += deltaTime; if (_deltaTime >= datastoreFrameDuration) { _deltaTime -= datastoreFrameDuration; try { WriteBuffer writeBuffer = _datastore.writeBuffer; // Unreliable _datastore.SerializeDeltaUpdates(false); if (writeBuffer.bytesWritten > 0) { _client.SendPersistenceMessage(writeBuffer.GetBuffer(), writeBuffer.bytesWritten, false); // Record delta update if local session capture is enabled and set to record if (sessionCaptureRecord) { _sessionCapture.WriteDeltaUpdate(_time, clientID, writeBuffer.GetBuffer(), writeBuffer.bytesWritten, false, 0, false); } } // Reliable _datastore.SerializeDeltaUpdates(true, _nextUpdateID); if (writeBuffer.bytesWritten > 0) { _client.SendPersistenceMessage(writeBuffer.GetBuffer(), writeBuffer.bytesWritten, true); // Record delta update if local session capture is enabled and set to record if (sessionCaptureRecord) { _sessionCapture.WriteDeltaUpdate(_time, clientID, writeBuffer.GetBuffer(), writeBuffer.bytesWritten, true, _nextUpdateID, false); } // Only increment if data was written _nextUpdateID++; } } catch (Exception exception) { Debug.LogException(exception); Debug.LogError("Failed to serialize datastore message. Disconnecting."); Disconnect(true); } } }