EditorOnly tag workflow and asmdef.

Hey,

Not quite sure if it’s correct to flag the subject as “bug”, but it seems relevant to me at the moment. I will change it if required.

We are relying heavily on the EditorOnly tag of Unity to optimize our level design process. It’s really helpful to have a component and object-based post-process on your objects, especially mixed with our level editor.

Our level designer scripts are grouped in a folder having its own asmdef and are included only in Editor, since they are useless in build (and often contain editor code like PrefabUtility calls).

At our biggest surprise, Unity will refuse to have a script defined in Editor via an asmdef onto an EditorOnly game object:

If the game object is EditorOnly, then the script won’t be present at runtime, so it shouldn’t matter. We feel like there is a flaw in the whole “editor only” process of the Unity editor.

Is this an expected behaviour that will remain this way, or should it be fixed?

On a side note, it’s important to be aware that, as far as I know, the EditorOnly tag doesn’t work for prefabs instantiated at runtime, making this “script doesn’t exist at runtime” warning more relevant. Maybe this prefab behaviour should be considered an issue as well?

I don’t think Unity will want to bring editor scripts into the runtime to then strip them back out. Code stripping is pretty finicky, so it’ll likely cause issues.

However, you can implement your tools outside of the scene and if you really need it, store runtime data containers on GameObjects and strip them yourself. I’ve built many tools this way and almost never found a reason for editor code to live in the scene.

Are there any concerns that can’t be worked around this way?