Destroyed Gameobject Save

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
NeatMaddness
Posts: 1
Joined: Thu Nov 23, 2017 5:48 pm

Destroyed Gameobject Save

Post 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!
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Destroyed Gameobject Save

Post 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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Locked