Accessing public variable in MonoBehaviour script from EditorWindow

Hi guys,

I got 2 classes. The first one looks like this:

public class Generator : MonoBehaviour {
    public GameObject bodyRig;
//...
}

And the second one looks like this:

public class VisualJointEditor : EditorWindow {
    GameObject bodyRig;
//...
}

I want both GameObjects to be the same. The GameObject in the first class can be easily assigned in the Editor. Now I want that the GameObject of the VisualJointEditor can access the GameObject of the Generator class.

Is it possible to access a public variable from the EditorWindow class?

If the public variable would be static, I could access it - but how can I, when it is not? Because a static variable can not be assigned in the Editor :frowning:

Thanks for any help :slight_smile:

u can try smth like bodyRig = GameObject.FindObjectOfType(typeof(Generator)) as Generator; in ur editor window script

Perfect. Thanks!

if(generatorScript == null) {
   generatorScript = GameObject.FindObjectOfType(typeof(Generator)) as Generator;
   bodyRig = generatorScript.bodyRig;
}