- Home /
Editor scripting: Object reference not set to an instance of an object
Hi!
I have a Unity Editor script, and I need to manage arrays.
I'm already correctly using two arrays, and I need a third one of int type, but even when doing the exact same process I used to get and set the data from the other two, I get the "Object reference not set to an instance of an object" error.
Where the problem could be?
First part of editor script (I get the error in GetFrameNumbersArray(), inside the "for"):
[CustomEditor(typeof(MenuButtonsGeneratorVR))]
public class MenuEditorVR : Editor {
private SerializedObject m_Object;
private SerializedProperty m_MenuItems;
private SerializedProperty m_Textures;
private SerializedProperty m_ScenesIndexes;
private SerializedProperty m_Animations;
private SerializedProperty m_FramesNumber;
public void OnEnable() {
m_Object = new SerializedObject(target);
m_MenuItems = m_Object.FindProperty("m_MenuItems");
m_Textures = m_Object.FindProperty("m_Textures");
m_ScenesIndexes = m_Object.FindProperty("m_ScenesIndexes");
m_Animations = m_Object.FindProperty("m_Animations");
m_FramesNumber = m_Object.FindProperty("m_FramesNumber");
}
private static string framesNumberArraySizePath = "m_FramesNumber.Array.size";
private static string framesNumberArrayData = "m_FramesNumber.Array.data[{0}]";
// Get the array elements
private int[] GetFrameNumbersArray() {
var framesArray = new int[m_MenuItems.intValue];
for (int i = 0; i < m_MenuItems.intValue; i++) {
framesArray[i] = m_Object.FindProperty(string.Format(framesNumberArrayData, i)).intValue;
}
return framesArray;
}
// Set a new array element
private void SetFramesNumberIndex(int i, int index) {
m_Object.FindProperty(string.Format(framesNumberArrayData, i)).intValue = index;
}
I obviously have a m_FramesNumber public int array variable in the script affected by this, but it still throws an error when calling the GetFrameNumbersArray() method and entering the "for" statement.
Any help is really appreaciated.
Thanks for your time and have a nice day!
Your answer
Follow this Question
Related Questions
How can I recreate the Array Inspector element for a custom Inspector GUI? 7 Answers
EditorGUI add SortingLayer-like list to custom Editor 1 Answer
Get the highlighted variable in the inspector 0 Answers
Create inspector drop-down button based on the content of a list in editor mode 1 Answer
Is it possible to drag/drop/increment into editor array? 1 Answer