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.

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].

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.