- Home /
Preserving the custom inspected Target object between play states
Hello,
I've been following a youtube tutorial on doing a custom inspector in the context of doing 2D tile map editor.
The Custom Editor script starts off as:
[CustomEditor(typeof(TileWorld))]
public class TileGridEditor : Editor
{
TileWorld tileWorld;
void OnEnable()
{
if (!tileWorld.hasBeenInitialized)
tileWorld.Initialize();
}
.....
Now, I have written all my needed functions within the TileWorld class, and am frequently calling them from the Editor script, like .
A crucial part of TileWorld class is a GameObject[][] reference list of all tiles currently making up the game world. I have written code to translate world coordinates into X and Y indices of the 2D array, and the setup is working fine, until I enter and exit a "Play" state from the editor.
At that part, the child objects (world tiles) do remain within my scene, but the tileWorld reference appears to be reset and the Gameobject 2D array list is apparently re-initialized anew and is now completely empty.
Question - How to preserve the target instance from the Editor script, in it's current state before entering Play mode, and then restore it after exiting Play mode so that I can edit my tile set further, instead of manually deleting all tiles and starting again? In fact, how come this doesn't happen automatically?
Thank you!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How can I make function run in the editor only when I press a button in the inspector? 1 Answer
Why does my custom property drawer's DragAndDrop add items twice? 2 Answers
How to detect if project is Using new or Old Input System via code? 1 Answer
EditorGUI add SortingLayer-like list to custom Editor 1 Answer