Saving and loading references

When you save a class or script, by default Easy Save will store it’s fields by reference if they inherit from UnityEngine.Object.

To do this, Easy Save has a reference manager which stores IDs for the references in your scene.

Reference managers are scene-specific, so you should have one in every scene in which you’re saving and loading references. You shouldn’t put it in a prefab or mark it as DontDestroyOnLoad.

When you save a scene, Easy Save will automatically add the following references to the reference manager:

  • All GameObjects and Components in your scene
  • All UnityEngine.Object references stored in your Components.
  • All prefabs which are referenced by your scene and have an ES3Prefab Component attached

When you make a change in a scene, Easy Save will add or update the references of the modified object to the reference manager.

Sometimes the reference manager will keep references to things which are no longer used by your scene.

To remove any references from the manager which are not directly referenced by your scene, press the Optimize button on the ES3 Reference Mgr component of the Easy Save 3 Manager in your scene.

To manually add an asset to the reference manager, right-click it and press Add Reference(s) to Manager while the scene containing the manager is open.

Sometimes it is necessary to exclude objects from a manager, for example if an Editor-only object has the wrong hide flags are assigned and shouldn’t be added to the manager. To manually exclude an asset from the reference manager, right-click it and press Exclude Reference(s) from Manager while the scene containing the manager is open.

For projects with a large number of objects it’s sometimes necessary to manually manage references to improve Editor performance. For more information on doing this please see the Improving Editor Performance section of the Improving Performance guide.

Deleting a reference manager will usually invalidate any existing save data you have, because the reference IDs will no longer exist. Re-adding the reference manager will generate new IDs, so the save data will still be invalid.

In this case you can either roll back your project to a time before you deleted the reference manager, or you would need to manually change the reference IDs in the ES3ReferenceMgr’s ‘References’ foldout to match those in the save file.

In some cases you might get a warning which looks like this:

“Reference with ID 123456789 could not be found in Easy Save’s reference manager.”
or
Reference for MyType with ID 123456789 could not be found in Easy Save’s reference manager.”

In most cases this is normal and doesn’t indicate any issues, for example when saving and loading prefab instances. However, if you are finding that fields are missing references then this warning likely points to the issue.

If you’re saving something which references an object which has been created at runtime then this means that object no longer exists. Most commonly it’s because this object hasn’t been saved and loaded, or has been loaded after the object which references it has been loaded. In this case you would need to save and load that object separately before saving or loading anything which references it.

If you can’t guarantee the order in which objects are loaded (this is often the case with Auto Save) then you may need to load twice: once to load the instances, and again to load references to them.

If the missing reference is for a Texture, Material or Mesh it could be that you’re modifying the object at runtime, or you are using a Renderer’s material field. When this happens Unity creates a new instance of these objects which will no longer exist when you exit playmode. The solution to this is the same as above for objects created at runtime.

If the missing reference is for an object which was not created or modified at runtime then it usually means that the object isn’t a dependency of your scene, so never gets added to the reference manager. In this case right-clicking the object while your scene is open in the Edtior and selecting Easy Save 3 > Add Reference(s) to Manager will add the object to the reference manager.