- Home /
Question by
RD_Dev · Jan 08, 2017 at 08:47 AM ·
c#unityeditorxmlcustom editor
Are unity objects ID is static in project?
Hi Guys. I use "smallObject" for store something from project.
public class checkResource : MonoBehaviour {
public UnityEngine.Object smallObject;
public string fileName = "Id.xml";
}
I want to save a snapshot of this gameObject state. I save public unityengine.object Id to XML:
" <resourceId>9230</resourceId>"
When I need to recover state, I load Id form xml and take object by his ID:
((checkResource)target).smallObject = EditorUtility.InstanceIDToObject(result.resourceId);
Can I'll be sure, that IDs in project will stay as constant.
Thank you.
Comment
Answer by RD_Dev · Jan 09, 2017 at 08:09 AM
I figured out. Id will not be static.
Solution is saving resource paths
resourcePath = UnityEditor.AssetDatabase.GetAssetPath(rObject.GetInstanceID());
And loading it back
rObject = UnityEditor.AssetDatabase.LoadAssetAtPath(resourcePath, typeof(UnityEngine.Object));