- Home /
Saving data made using the editor
I've made an editor script that attaches various kinds of data to an object, but when I close the editor and reopen (without changing the script), it doesn't remember the state of any of the assigned data. All of it is public variables.
Data includes:
boolean
2D array of Vector3
2D array of game objects
integers
floats
When I reopen Unity, all of this seems to be forgotten.
How do I make it remember all the things I've done using editor scripts for all of the data?
EDIT: How the editor script works is that it interacts with the GameObject's script in such a way that if the GameObject's Vector3 2D array is null, it goes to the 'creation' side of the menu, otherwise it goes to the 'editor' side of the menu.
Whenever I start Unity, it always ends up on the 'creation' side of the menu, which tells me the array is being forgotten, but I'm not sure.
file -> save project or file -> save scene. And if you're using prefabs a safe way is to 'apply' the changes
I do save before closing, but I tried specifically using the menu to save and it still 'forgets'.
I will add more details to the post in case I was not specific enough.
$$anonymous$$ight be easier to diagnose if you show your editor script and the script which represents the object being edited.
Answer by MasterLG · Aug 30, 2013 at 04:41 PM
Apparently you can only save arrays if they're 1 dimensional. Took a bit of math-ing, but I reduced all the 2D arrays into 1D arrays and now things are saving. As far as I can tell.
I usually create wrapper methods for 2D array simulation:
private int columns = 100;
private int rows = 100;
private int[] someArray = new int[columns * rows];
public int GetItem(int row, int column) {
return someArray[row * columns + column];
}
public void SetItem(int row, int column, int item) {
someArray[row * columns + column] = item;
}
// Then just use like this:
SetItem(5, 2, GetItem(5, 3));
Answer by darkForester · Aug 29, 2013 at 02:29 PM
I am not sure if this is the solution to your exact problem, but sometimes you may need to use EditorUtility.SetDirty.
This method tells Unity that the object has changed in some fashion and needs to be serialized.
Also, make sure your script has [System.Serializable] attribute attached and each field should be marked with [SerializeField].
you dont need to, if the variables are public and as far as i know monobehaviours are serialized frequently by default. EditorUtility.SetDirty needs to be used if you use an Editor script, which i think he isn't.
@ValooFX OP has tagged question as "editor script" and "editor" so I guess that SetDirty
is relevant in this case.
I tried adding the attributes and using SetDirty, but it didn't work.
I applied SetDirty after I finished the 'create' process, so after I set up all the variables and create the objects and stuff.
EDIT: In the original post, I wrote that I'm using editor scripts and it's data created by these that's not saving.