Saving and Loading Prefabs Instantiated at Runtime

Examples using Easy Save's API code
Post Reply
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Saving and Loading Prefabs Instantiated at Runtime

Post 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.
Attachments
Saving and Loading Prefabs Instantiated at Runtime.unitypackage
(50.3 KiB) Downloaded 731 times
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply