Hello,
ES3 works great for me. Thank you. I've added a feature that allows selected data in my app to be saved/loaded. This works well, except for 1 edge case: Sometimes the original object (goID) is still there (but with different properties). In that case, I want to create a new instance, rather than loadInto the existing one.
In order to do that, I need to check unique IDs. Before I implement that myself, I wanted to see if I could do it using the ES3 property "goID".
How is goID generated for an ES3 file? Can I look for goID in an existing gameobject at runtime?
Appending Save/Load Data - How is goID generated?
Re: Appending Save/Load Data - How is goID generated?
Hi there,
The goID is just the reference ID of a GameObject, so you can lookup a reference ID using ES3ReferenceMgr.Current.Get(id), presuming that GameObject still exists.
All the best,
Joel
The goID is just the reference ID of a GameObject, so you can lookup a reference ID using ES3ReferenceMgr.Current.Get(id), presuming that GameObject still exists.
All the best,
Joel
Re: Appending Save/Load Data - How is goID generated?
I was able to achieve what I wanted (and what you suggested) by adding some code inside the ES3ComponentType.ReadObject<T>(ES3Reader reader) method.
While I don't like modifying source code, all the references I need are right there and this seems like the least disruptive option to an already working system. Would you agree? Or is there a better/simpler way?
Code: Select all
else if (propertyName == gameObjectPropertyName)
{
//ES3 Source Code
//long goID = reader.Read_ref();
//if (instance != null)
// break;
//var go = (GameObject)refMgr.Get(goID, type);
//My Attempt Below
long goID = reader.Read_ref();
objExists = ES3ReferenceMgr.Current.Get(id);
if (instance != null && objExists == null)
break;
var go = (GameObject)refMgr.Get(goID, type);
if (objExists != null)
{
go = null;
goID = Simulator.Utils.GetNewEasySaveReferenceID();
id = Simulator.Utils.GetNewEasySaveReferenceID();
}
if (go == null)
{
go = new GameObject("Easy Save 3 Loaded GameObject");
#if UNITY_EDITOR
go.AddComponent<ES3InspectorInfo>().SetMessage("This GameObject was created because Easy Save could not find a GameObject in the scene with the same instance ID as the GameObject the Component we are loading is attached to.\nTo prevent this from being created, use the LoadInto methods to tell Easy Save what Component the data should be loaded in to.");
#endif
refMgr.Add(go, goID);
}
instance = GetOrAddComponent(go, type);
refMgr.Add(instance, id);
break;
}
Re: Appending Save/Load Data - How is goID generated?
Hi there,
As far as I can tell you can achieve the same thing by using ES3.LoadInto on a new instance. I.e.
var go = Instantiate(prefab);
ES3.LoadInto(“key”, go);
All the best,
Joel
As far as I can tell you can achieve the same thing by using ES3.LoadInto on a new instance. I.e.
var go = Instantiate(prefab);
ES3.LoadInto(“key”, go);
All the best,
Joel