Reputation: 4124
I am attempting to create a custom editor unity script.
I need to access a private variable that I have exposed via property.
However, the property is not accessible using the Editor script.
I am trying to access the MyObjects
property in the custom editor.
My Class
public class MySpecialClass : MonoBehaviour {
[SerializeField]
private GameObject[] myObjects;
public GameObject[] MyObjects {
get {
return myObjects;
}
set {
myObjects = value;
}
}
}
My Custom Editor script
using UnityEditor;
[CustomEditor(typeof(MySpecialClass))]
public class MySpecialClassEditor : Editor {
private bool[] showMyObjectSlots = new bool[MySpecialClass.MyObjects.Length];
}
Why wouldn't a public property be accessible in to the CustomEditor?
Upvotes: 0
Views: 1405
Reputation: 7579
You need an instance to access the non-static MyObjects
property. The instance can be found through the target
field in your custom editor. The field target
is of type UnityEngine.Object
, but it points to an object of the type of the MonoBehaviour
of which the class is a custom editor (the argument in the CustomEditor
attribute), and hence can be casted to it.
Upvotes: 2