Figure: Diagnostic workflow: Editor-only assembly → Reference runtime assembly → Verify player compilation
Figure: Diagnostic workflow: Editor-only assembly → Reference runtime assembly → Verify player compilation

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

  1. Add a dedicated Editor-only assembly definition.
    First error, references and target environment
    First error, references and target environment
  2. Reference Runtime from Editor, without a reverse Runtime-to-Editor dependency.
    First error, references and target environment
    First error, references and target environment
  3. Check package references, namespaces, constraints, and automatic references from the first compiler error.
    First error, references and target environment
    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

  1. Identify the assembly actually containing each file.
    First error, references and target environment
    First error, references and target environment
  2. Restrict the Editor assembly to Editor and reference the runtime assembly.
    First error, references and target environment
    First error, references and target environment
  3. Remove runtime references to Editor types/assemblies and build a Player.
    First error, references and target environment
    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

References