-2

I am using Unity UI Toolkit to create an editor window, the problem is when I make a change in the code and unity recompile it, I lose every thing (values) in the editor window. I am using a listview of objectfields and vector3 and toggle elements. How do I save elements values between compiles (or when I close and reopen the editor window)?

ouzari
  • 397
  • 3
  • 12
  • Make sure the fields are serializable inside of your window. It uses the same rules that apply to MonoBehaviours. Make the fields public or decorate with [SerializeField]. This solves the compile problem. For retaining between sessions, use EditorPrefs as noted below. – hijinxbassist May 30 '23 at 16:56

1 Answers1

0

The easiest way to store your data inside the editor is to use EditorPrefs.

You can also use ScriptableObjects or Json files like it is shown here.

EditorPrefs are just to store data locally for your editor preferences and are not avaiable at runtime. In the case you need access at runtime you need to go with one of the other two options.