Saving and Loading a List of Gameobjects

Discussion and help for Easy Save 3
Post Reply
elderhank
Posts: 2
Joined: Sat Aug 12, 2023 10:24 pm

Saving and Loading a List of Gameobjects

Post by elderhank »

In my scene I have an empty gameobject I'm using as a "container" for a number of other gameobjects, which are children of the container gameobject. When the player moves next to one of the child gameobjects, the object is destroyed, and when they drop an item from their inventory a gameobject is instantiated as a child of the container gameobject. I'd like to have all of the gameobjects in the container saved so that the item's positions and rotations are as the player left them, but I haven't gotten anything to work yet.

I've tried using a list of the child gameobjects which is saved in OnApplicationQuit. When loading the gameobjects from the saved list, the script first destroys all of the child gameobjects and then attempts to repopulate the runtime list with the gameobjects from the saved list, but the gameobjects in the runtime list all show up as "Missing." I assume this is because I destroyed all of the gameobjects the saved list was referencing, but I can't think of a way to have the saved list reference the object in a different way (that doesn't reference the instance of the object that I'm going to end up destroying). I tried having the list save the prefab the gameobject was derived from instead of the prefab instance, but I got an error stating that reparenting a prefab was disabled to prevent data corruption.

Any suggestions on how to go about doing this?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving and Loading a List of Gameobjects

Post by Joel »

Hi there,

Please could you show me the code you are using to save and load. Also just to check, have you followed the Saving GameObjects guide, and are you using the latest version of Easy Save?

https://docs.moodkie.com/easy-save-3/es ... s-prefabs/

Also regarding the error message you're getting, this is because you're trying to save a prefab rather than a prefab instance.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
elderhank
Posts: 2
Joined: Sat Aug 12, 2023 10:24 pm

Re: Saving and Loading a List of Gameobjects

Post by elderhank »

Actually I figured it out! I needed to find a way to load the gameobjects into the list and then replace those gamobject with their respective prefabs before destroying the instances of them, but I was trying to load the prefabs of the gameobjects directly from Easy Save (which was not allowed by Unity).
Post Reply