Cause and mechanism
An asmdef file defines which C# files compile together into an assembly. Keep code using UnityEditor separate from game code, and reference only the required assemblies. Check platform restrictions and reference direction in the asmdefs rather than relying on an Editor folder name alone.
Check and correct the setup
- Add a dedicated Editor-only assembly definition.
First error, references and target environment - Reference Runtime from Editor, without a reverse Runtime-to-Editor dependency.
First error, references and target environment - Check package references, namespaces, constraints, and automatic references from the first compiler error.
First error, references and target environment
Limits and verification
Editor compilation alone does not verify player compilation. Check a target-platform build.
A focused diagnostic setup
Isolate one runtime class and its custom inspector. Build a small one-way dependency from Editor to Runtime.
Test in this order
- Identify the assembly actually containing each file.
First error, references and target environment - Restrict the Editor assembly to Editor and reference the runtime assembly.
First error, references and target environment - Remove runtime references to Editor types/assemblies and build a Player.
First error, references and target environment
Interpret the result
An enclosing asmdef can change what an Editor folder implies. Missing runtime types in Editor and leaking Editor types into Player are opposite dependency problems; do not solve them with mutual references.
Related explanations
- Check player build errors from UnityEditor references
- Investigate asmdef dependencies and repeated compilation