CopyStateForBackgroundThreadSave method

StoryState CopyStateForBackgroundThreadSave()
Advanced usage! If you have a large story, and saving state to JSON takes too long for your framerate, you can temporarily freeze a copy of the state for saving on a separate thread. Internally, the engine maintains a "diff patch". When you've finished saving your state, call BackgroundSaveComplete() and that diff patch will be applied, allowing the story to continue in its usual mode.

Implementation

StoryState CopyStateForBackgroundThreadSave() {
  ifAsyncWeCant('start saving on a background thread');
  if (_asyncSaving) {
    throw Exception(
        "Story is already in background saving mode, can't call CopyStateForBackgroundThreadSave again!");
  }
  var stateToSave = _state;
  _state = _state.copyAndStartPatching();
  _asyncSaving = true;
  return stateToSave;
}