Page 1 of 1

Saving and Loading Prefabs Instantiated at Runtime

Posted: Sun Oct 30, 2022 1:53 pm
by Joel
Saving and Loading Prefabs Instantiated at Runtime

This example demonstrates how to save and load prefabs instantiated at runtime. To use, import it into a project containing Easy Save and open the scene located at Assets/Easy Save 3/Examples/Saving and Loading Prefabs Instantiated at Runtime/.

It uses a single script named PrefabManager.cs which provides three methods:
  • CreateRandonPrefab(): Creates a random prefab at a random location and adds it to a list named prefabInstances.
  • Save prefab instances: Saves all prefab instances which were created.
  • Saves the prefab instances which were previously saved.
To see how this example works, open the PrefabManager.cs script and read the comments within.

If you were to create this example from scratch you would need to set up the scene as follows (this isn't required if using this example):
  • Add an Easy Save 3 Manager to the scene by going to Tools > Easy Save 3 > Add Manager to Scene.
  • Enable Easy Save for every prefab by right-clicking each of them and selecting Easy Save 3 > Enable Easy Save for Prefab.
  • Add a PrefabManager.cs script to any GameObject in the scene.
  • Drag your prefabs into the 'prefabs' array of the PrefabManager script.
  • Create buttons to call the methods of the PrefabManager script.