Saving and Loading

Saving in Narramancer takes the nouns plus any verbs and serializes them down into a save file, that can then be loaded at a later time. Verbs are built in such a way that even if it is in the middle of running an action, it remembers where it was and what it was doing, and can pick up right where it left off when re-loaded.

Serializing Parts of a Scene

In addition to verbs and nouns, you will probably need various aspects of your scene saved. In order to tell Narramancer which GameObjects need to be remembered, you must attach various Narramancer components to them.

SerializeActive

The SerializeActive component will save and restore whether the attached GameObject is set to Active or disabled.

SerializeTransform

The SerializeTransform component will save and load all aspects of a GameObject's Transform, including its position and rotation. This component is required to use Translate and Rotate Nodes on a GameObject.

SerializeImage

The SerializeImage component will save and load all aspects of a GameObject's Image, specifically it's sprite and the texture assigned..

SerializeRectTransform

The SerializeRectTransform component will save and load all aspects of a GameObject's RectTransform, including its position and layout values.

SerializeText

The SerializeText component will save and load the text value of a GameObject's Text Component.

SerializeSpriteRenderer

The SerializeSpriteRenderer component will save and load the sprite assigned to a GameObject's SpriteRenderer.

SerializeAnimation

The SerializeAnimation component will save and load the values of a Unity.Animation component, including the currently playing animation.

SerializeAudioSource

The SerializeAudioSource component will save and load the values of a Unity.AudioSource such as the currently playing clip, volume, pitch, and whether the clip is looping. It will NOT, however, save or restore audio played using OneShot.

Saving the Relationship Between a Noun and a GameObject

If a NounInstance is associated with a GameObject it is highly recommend to add a SerializeNounInstanceReference component to that GameObject in order to maintain that relationship after a load.

SerializableMonoBehaviour

If the needs of your game are not met by the above components it is simply a matter of writing a custom component.

Simply create a new component that either extends from SerializableMonoBehaviour OR implements ISerializableMonoBehaviour.

If your component extends from SerializableMonoBehaviour, any appropriate fields with the SerializeMonoBehaviourFieldAttribute attached to them will automatically be stored on save and assigned on load. In more complex cases, you may need to override either or both Serialize() and Deserialize() and perform additional logic by assessing the StoryInstance (just be sure to call the base.Serialize() and base.Deserialize()).