0
\$\begingroup\$

I'm writing a custom inspector for my asset (by deriving from Editor), and I have a few variables controlling the state of the inspector (like whether a foldout is opened or not), that I'd like to be saved. I don't want to put them on the object, since then it would end up as junk inside the game state, but I also don't want it to be reset every time I click away from the object and then click back.

Do you guys have an idea where could I put the data so it gets persisted?

\$\endgroup\$
  • \$\begingroup\$ I think if you just make it a member variable of your editor class, it will only reset the variables when scripts recompile. Which many unity standard editors do anyways. This also keeps editor code out of your class, which is ideal. However if you really want data to persist even between compilations, then you should go with DMGregory's answer \$\endgroup\$ – gjh33 Apr 4 at 20:10
0
\$\begingroup\$

I'd recommend putting this type of state information inside an #if UNITY_EDITOR conditional compilation block inside the type you're editing. That way it's stored in memory only in the editor, and stripped out of the built game executable by the preprocessor.

It stays associated with the object you were editing, and can be serialized to persist between editing sessions.

\$\endgroup\$
  • \$\begingroup\$ Thanks! Actually that's a great idea! \$\endgroup\$ – torgabor Apr 5 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.