# How to add state to the custom inspector in Unity

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?

• 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 – gjh33 Apr 4 at 20:10

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.