Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Why can't i build while having EditorSnapSettings in my script?

Discussion in 'Editor & General Support' started by Maxrabinho, Mar 25, 2023.

  1. Maxrabinho

    Maxrabinho

    Joined:
    Feb 21, 2023
    Posts:
    1
    I used EditorSnapSettings.move in my scripts, and it would give me no problem while i was on the editor, the game would run perfectly fine. But as soon as i tried to build the game, i'd get this error. I fixed this already by changing the whole UnityEditor.EditorSnapSettings.move.x line for just the value i had on the Grid Snapping (which is 10). I just wanted to know why can't i build while having EditorSnapSettings.move in my script? Thanks for reading
     

    Attached Files:

    • 1.png
      1.png
      File size:
      43.6 KB
      Views:
      57
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,607
    You need to ensure any editor code is not being built into your project; this is a fundamental rule of building games in Unity, as Unity's editor API is not available at build time.

    There's a few ways to follow this requirement, such as putting your editor only scripts in folders named 'Editor', using editor only assembly definitions, or surrounding the editor-only code in
    #if UNITY_EDITOR
    pre-processor directives.
     
    Maxrabinho likes this.