Page 3 of 3

Re: Creating an Automatic Save Structure

Posted: Fri Jul 14, 2017 5:03 am
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);
                }  

Re: Creating an Automatic Save Structure

Posted: Fri Jul 14, 2017 7:07 am
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

Re: Creating an Automatic Save Structure

Posted: Fri Jul 14, 2017 8:54 am
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. ;)

Re: Creating an Automatic Save Structure

Posted: Fri Jul 14, 2017 9:45 am
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

Re: Creating an Automatic Save Structure

Posted: Fri Jul 14, 2017 11:06 am
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