unity – How can I make a level generator script run in Edit Mode?


I’ve a script that takes in a PNG bitmap (e.g. 8×8) and, reading from that, populates the grid with cells where alpha > 0.


The script runs in Awake(), so it can only be seen in Play Mode. I want it to always appear in the scene, even in Edit Mode.

Potential Solutions

I know of the (ExecuteInEditMode) attribute, as well as the OnValidate() callback. I don’t know which is better to use, though, or what pitfalls to avoid.

Additionally, in the past, I created a level generator that created a mesh, which I saved as an .asset with a customer editor button. The .asset was then loaded from inside the script. However, if possible, I’d like a more elegant — and automatic — solution.


I’m using Unity 2018.4, and the grid is isometric. (I’m not using Unity’s built-in Tilemap.)