Search Unity

Editor Folder Scripts not find my other scripts

Discussion in 'Editor & General Support' started by LatchGameDev, Nov 24, 2014.

  1. LatchGameDev

    LatchGameDev

    Joined:
    Nov 24, 2014
    Posts:
    61
    I'm sure this is an easy fix but I can't seem to find the answer in google or the documentation.

    I wanted to make a custom inspector. I placed a script called ActionNodeEditor in the editor folder and it can't access any of my other scripts. and here is my code.

    Code (csharp):
    1.  
    2.  
    3. using UnityEngine;
    4. using System.Collections;
    5. using UnityEditor;
    6.  
    7. [CustomEditor(typeof(NodeAction))] // Line that errors out. NodeAction can't be found
    8. public class ActionNodeEditor : Editor
    9. {
    10.  
    11.     // Use this for initialization
    12.     void Start () {
    13.    
    14.     }
    15.    
    16.     // Update is called once per frame
    17.     void Update () {
    18.    
    19.     }
    20. }
    21.  
    22.  
    The [CustomEditor(typeof(NodeAction))] can't find the NodeAction class. I confirmed it was because it wasn't in the same section as my other scripts. So from the Assembly-CSharp-Editor section of mono develop how do I reference the Assembly-CSharp scripts.

    P.S. I also uploaded a picture of mono develop as an attached file if you want to look at it.
     

    Attached Files:

  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    In which folder is NodeAction and in which one is ActionNodeEditor? Just give the exact location within the Unity project.
    Do you have this error message in Unity or just in MonoDevelop?
     
  3. LatchGameDev

    LatchGameDev

    Joined:
    Nov 24, 2014
    Posts:
    61
    Almost all of the scripts are located in Assets/Scripts/NodeAction.cs and the one editor script is located in Assets/Editor/NodeActionEditor.cs

    I only have the error in MonoDevelop but unity is not showing anything different like the script isn't running. Made a small change to see if it would blank out my inspector which it did not.

    Code (csharp):
    1.  
    2.  
    3. using UnityEngine;
    4. using System.Collections;
    5. using UnityEditor;
    6.  
    7. [CustomEditor(typeof(NodeAction))]
    8. public class ActionNodeEditor : Editor
    9. {
    10.  
    11.     public override void OnInspectorGUI()
    12.     {
    13.  
    14.     }
    15. }
    16.  
    17.  
    This is the start of the other class

    Code (csharp):
    1.  
    2.  
    3. using UnityEngine;
    4. using System.Collections;
    5.  
    6. [SerializeAll]
    7. public class NodeAction : NodeInterface {
    8. ...
    9.  
    10.  
     
  4. LatchGameDev

    LatchGameDev

    Joined:
    Nov 24, 2014
    Posts:
    61

    If I put the node action class in the same folder as ActionNodeEditor.cs then it will find the class. I should also let you know it's not just node action. Any script in the editor folder can not see any script in the Assembly-CSharp/Scripts/ section of MonoDevelop
     
  5. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    There are often "wrong" error messages in MonoDevelop. Just close it and open it again or sync it from Unity. This usually gives you the correct results again.
    Custom editor scripts only work for classes inheriting from MonoBehaviour. That means it will only work if NodeInterface somehow inherits from MonoBehaviour.
    You may consider to use property drawers for other classes: http://docs.unity3d.com/ScriptReference/PropertyDrawer.html
     
    Last edited: Nov 24, 2014
  6. LatchGameDev

    LatchGameDev

    Joined:
    Nov 24, 2014
    Posts:
    61
    Thank you for your help Dantus. Didn't know I had to inherit from MonoBehavior before even tho in my case NodeInterface was.

    Code (csharp):
    1.  public class NodeInterface : MonoBehaviour
    I'm pretty sure just restarting unity and MonoDevelop would have fixed it but I accidently fixed it another way. I'll look into PropertyDrawer since I like to know all my options for something.

    For anyone else having this problem. This is strangely how I fixed it.

    1. Move the script from the editor folder to the assets/script folder
    2. Restart mono and make sure you can now find your classes
    3. Hit the play button
    4. Move the script back to the editor folder after it gives you an error saying it needs to be in the editor folder
    5. If it's not fixed restart unity and MonoDevelop

    If I ever come across this problem again I'll make sure to validate these steps and/or find out if a simple restart works.

    Version of ActionNodeEditor.cs that I had when it gave me the error (step 4):
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using UnityEditor;
    5.  
    6. [CustomEditor(typeof(NodeAction))]
    7. public class ActionNodeEditor : Editor
    8. {
    9.  
    10.     public override void OnInspectorGUI()
    11.     {
    12.         NodeAction nodeAction = (NodeAction)target;
    13.  
    14.         nodeAction.itemID = EditorGUILayout.IntField ("An Int", nodeAction.itemID);
    15.     }
    16. }
    17.  
    18.  
     
  7. Hobby-Game-Developer

    Hobby-Game-Developer

    Joined:
    Aug 27, 2017
    Posts:
    14
    For anyone reading this and can't find a fix here:

    I had the same issue.


    ----------


    **The solution :**


    ----------


    **1.** Go to your Projectmap-Explorer (I am German and don't know how it's called in English).


    ----------


    **2.** Right click on References and then left click on "add references". The reference-manager-window should open.


    ----------


    **3.** On Assembly and Project, search the "Accessibility"-reference toggle and click it true.


    ----------


    *Then click OK and your script should be able to reference all of your classes now, no matter if in the editor or resources folder. You might have to repeat those steps from time to time, if it will uncheck automatically again, so keep it in mind.*
     
  8. RChrispy

    RChrispy

    Joined:
    Dec 18, 2013
    Posts:
    71
    Seems this issue is not solvable for vscode users right? :( Its rather unfortunate that I can debug and use vscode just fine but when it comes to Editor scripting it just wont work...