Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

When building project containing 2DTilemap, Unity doesn't find "SetEditorPreviewTile()"-function

Discussion in '2D' started by HuldaGnodima, Apr 2, 2021.

  1. HuldaGnodima


    Oct 10, 2016

    I think I may've found a bug, but I wanted to write here just in case someone knows if there's a fix for this. I'm using 2D Tilemaps in my project which plays/compiles fine in the Unity editor. However, when I try to build the project I get the following error:

    Code (CSharp):
    1. Assets\Scripts\SetTiles.cs(111,28): error CS1061: 'Tilemap' does not contain a definition for 'SetEditorPreviewTile' and no accessible extension method 'SetEditorPreviewTile' accepting a first argument of type 'Tilemap' could be found (are you missing a using directive or an assembly reference?)
    Since everything works fine up until I try to build the game (and the function SetEditorPreviewTile() does infact exist), I'm thinking this has to be a bug concerning Tilemap? I'm thinking I should send off a bug-report, but perhaps I'm wrong and there's some easy fix to this? Does anyone what I can do to fix this? Thanks in advance!

    Edit: If anyone encounters this problem, I didn't find a solution that used preview-Tiles. To solve it I made another identical TileMap I call "PreviewTilemap" and paint on/off actual tiles on it. It's a bit of a work-around but it works! I'll go with that for now : ) Hope it helps someone!
    Last edited: Apr 2, 2021
  2. MarekUnity


    Unity Technologies

    Jan 6, 2017
    Hi @HuldaGnodima, your SetTiles.cs script contains code that is using UnityEditor. Editor scripts aren’t available in builds at runtime. To fix it, you can move your code to Editor folder, or put your editor code in between #UNITY_EDITOR directive
    Code (CSharp):
    1. #if UNITY_EDITOR
    2. using UnityEditor;
    4. Your Editor code
    5. ...
    6. ...
    8. #endif
    10. Your Runtime code
    MelvMay likes this.
  3. HuldaGnodima


    Oct 10, 2016
    Hi Marek, thank you very much for your reply!

    I see, I didn't know that UnityEditor.Editor-scripts were unavailable to builds, thank you for writing this! It makes a lot of sense. And I will use your fix!

    Have a great day :)
    MarekUnity likes this.