Z
Z
Zefirot2021-09-02 16:13:59
Unity
Zefirot, 2021-09-02 16:13:59

How to use the class in the editor?

I have a prefab to which a class is attached, let's say Test, in order to edit it in real time, I added it to the editor

using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(Test))]
public class TestEditor : Editor{
    public override void OnInspectorGUI(){
        base.DrawDefaultInspector();
        Test re = (Test)target;
        re.TestMethod();
..................................
        }
    }

Everything works until I use another class in the class, for example
using UnityEngine;
public class Test: MonoBehaviour{
  public void TestMethod(){
    if(VarA < DataStorage.instance.SomeVar){ .....

So everything works, but when editing, it gives an error saying "I don't know who DataStorage is ...".
Tell me how to use it in the editor?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pashara, 2021-09-02
@Zefirot

Zefirot , error is nullref. The object does not exist in the editor because DataStorage.instance is filled in Awake (which, in turn, will not work as you want in edit mode).
You need to write custom scripts for the editor, which will get data for the UI in a different way (load data from a file along the path , for example)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question