Search Unity

Question Why some editor scripts are working and some are not ?

Discussion in 'Editor & General Support' started by Chocolade, Aug 1, 2020.

  1. Chocolade

    Chocolade

    Joined:
    Jun 19, 2013
    Posts:
    933
    I have this simple editor script that create two buttons :
    When I'm using a breakpoint and then click on one of the buttons it's getting to the line inside for example to the line :

    Code (csharp):
    1.  
    2. Generate.GenerateNewMap();
    3.  
    The script :

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using UnityEditor;
    5.  
    6. [CustomEditor(typeof(TileMap))]
    7. public class CustomButton : Editor
    8. {
    9.     public override void OnInspectorGUI()
    10.     {
    11.         TileMap Generate = (TileMap)target;
    12.  
    13.         if (GUILayout.Button("Generate Map", GUILayout.Width(100), GUILayout.Height(30)))
    14.         {
    15.             Generate.GenerateNewMap();
    16.         }
    17.  
    18.         DrawDefaultInspector();
    19.  
    20.         if (GUILayout.Button("Destroy Map", GUILayout.Width(100), GUILayout.Height(30)))
    21.         {
    22.             Generate.DestroyMap();
    23.         }
    24.     }
    25. }
    26.  
    Then I created another script same folder in the assets same idea but when using a breakpoint it's never get inside :

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEditor;
    5. using UnityEngine;
    6.  
    7. [CustomEditor(typeof(TileMap))]
    8. public class TestEditor : Editor
    9. {
    10.     public override void OnInspectorGUI()
    11.     {
    12.         TileMap Generate = (TileMap)target;
    13.  
    14.         Debug.Log("Testing!");
    15.     }
    16. }
    17.  
    It's never get to the lines :

    Code (csharp):
    1.  
    2. TileMap Generate = (TileMap)target;
    3.  
    4. Debug.Log("Testing!");
    5.  
    I have another editor script is a bit long but it's not working either.


    When I add a breakpoint to the editor script with the buttons and then click on Attach to Unity then on the left it will be red circle so the breakpoint will work :



    but on the script I created for testing when I add a breakpoint it's showing a yellow circle on the left with some message :



    I don't understand it. What is the difference ? Why the first editor script is working and the breakpoints are working and on the second one it's not ? They are both in the same Editor folder.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,914
    You have two editors in the same project for the same type? I'm guessing Unity just finds and picks one of them and ignores the other. Since both of them would override the GUI for the object's inspector, I'm not sure what the expected behavior would be with two editors.