Page 1 of 1

Destroyed Gameobject Save

Posted: Thu Nov 23, 2017 6:33 pm
by NeatMaddness
Hey,

I am new to using this asset. What would be the best way to save/record if a certain gameobject in the level has been destroyed. For instance, if I have 1 ammo pickup gameobject in the level and the player has grabbed the pickup (thus destroying the gameobject), how would I save that it was been destroyed? The gameobject/ammo pickup is placed in the level from the editor, it is not created from script.

Let me know if there is more information you need and id be happy to go into more detail.

Thanks!

Re: Destroyed Gameobject Save

Posted: Fri Nov 24, 2017 7:41 am
by Joel
Hi there,

Attaching the following script to any object you want to record the destroyed status of would achieve this. Note that to Destroy a GameObject, you should call the script's Destroy method rather than Unity's Destroy method, as this allows Easy Save to detect it's been destroyed.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ES2RecordDestroy : MonoBehaviour 
{
	public string guid = System.Guid.NewGuid().ToString();

	void Start () 
	{
		if (ES2.Exists ("destroyedObjects.es2?tag=" + guid))
			Destroy (this.gameObject);
	}

	public void Destroy()
	{
		ES2.Save (true, "destroyedObjects.es2?tag=" + guid);
		Destroy (this.gameObject);
	}
}
All the best,
Joel