Creating an Automatic Save Structure

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Shockwolf
Posts: 14
Joined: Thu Feb 09, 2017 7:09 am

Re: Creating an Automatic Save Structure

Post by Shockwolf »

Thanks, but it doesn't seem to work.

I tried destroying the Child Objects both before and after calling the UniqueObjectManager.DestroyObject(this.gameObject); function and it still throws the same error and won't destroy the Parent Object Prefab that is supposed to be listed.

I tried this:

Code: Select all

// Destroy All Child Objects within this Object, if any.
                foreach (Transform child in transform)
                {
                    GameObject.Destroy(child.gameObject);
                }               
                // Now Destroy Parent Object.
                UniqueObjectManager.DestroyObject(this.gameObject);
And this:

Code: Select all

 

// Destroy Parent Object First.
UniqueObjectManager.DestroyObject(this.gameObject);

   // Destroy All Child Objects within this Object, if any.
                foreach (Transform child in transform)
                {
                    GameObject.Destroy(child.gameObject);
                }  
Regards, SW.
User avatar
Joel
Moodkie Staff
Posts: 4988
Joined: Wed Nov 07, 2012 10:32 pm

Re: Creating an Automatic Save Structure

Post by Joel »

Hi there,

I don't seem to be able to replicate this at my end. Would you be able to send me another test project with instructions so I can attempt to replicate it at my end?

Also note that Creating an Automatic Save Structure is only intended to be an example, so it will undoubtedly require some modification to suit your project which I cannot always assist with.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Shockwolf
Posts: 14
Joined: Thu Feb 09, 2017 7:09 am

Re: Creating an Automatic Save Structure

Post by Shockwolf »

Okay, try this...

Open up your "Creating an Automatic Save Structure" scene.

* Drag one of the prefabs used in this demo into the scene.
* Attach a new 3D Object to it (Parent it).
* Click "Apply" to update the prefab.
* Delete the prefab from the scene.

*Now press "Play".

*Wait for your Demo scene to instantiate the new prefabs that have an other object parented to it.
*Then watch what happens when your demo scene attempts delete one of the newly updated prefabs. ;)
Regards, SW.
User avatar
Joel
Moodkie Staff
Posts: 4988
Joined: Wed Nov 07, 2012 10:32 pm

Re: Creating an Automatic Save Structure

Post by Joel »

Thanks for clarifying, as usual it was me misinterpreting what you were saying :lol:

I've managed to find the issue, and an easy fix to handle children of prefabs which don't have Unique IDs attached: simply don't throw an exception.

i.e. Change this code on line 63 of the UniqueObjectManager:
// Remove prefab from createdPrefabs list, or throw error if it's not in list.
if(!CreatedObjects.Remove(obj))
	throw new System.Exception("Cannot destroy prefab: No such prefab exists.");
To this:
CreatedObjects.Remove(obj);
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Shockwolf
Posts: 14
Joined: Thu Feb 09, 2017 7:09 am

Re: Creating an Automatic Save Structure

Post by Shockwolf »

Thanks for clarifying, as usual it was me misinterpreting what you were saying :lol:
:lol: Hahaha! That's Okay, I'm getting used this! :D

// Remove prefab from createdPrefabs list, or throw error if it's not in list.
if(!CreatedObjects.Remove(obj))
	throw new System.Exception("Cannot destroy prefab: No such prefab exists.");
To this:
CreatedObjects.Remove(obj);
That's it! It Worked! Simple but effective... Again, thanks very Much Joel! :D
Regards, SW.
Locked