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.
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(NodeAction))] // Line that errors out. NodeAction can't be found
public class ActionNodeEditor : Editor
{
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
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.
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?
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.
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(NodeAction))]
public class ActionNodeEditor : Editor
{
public override void OnInspectorGUI()
{
}
}
This is the start of the other class
using UnityEngine;
using System.Collections;
[SerializeAll]
public class NodeAction : NodeInterface {
...
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
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: Unity - Scripting API: PropertyDrawer
Thank you for your help Dantus. Didn’t know I had to inherit from MonoBehavior before even tho in my case NodeInterface was.
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.
Move the script from the editor folder to the assets/script folder
Restart mono and make sure you can now find your classes
Hit the play button
Move the script back to the editor folder after it gives you an error saying it needs to be in the editor folder
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):
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(NodeAction))]
public class ActionNodeEditor : Editor
{
public override void OnInspectorGUI()
{
NodeAction nodeAction = (NodeAction)target;
nodeAction.itemID = EditorGUILayout.IntField ("An Int", nodeAction.itemID);
}
}
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.
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…