I’m Very Disappointed In Using ExecuteInEditMode(), Whenever I’m Dealing With Arrays And Lengths, The ExecuteInEditMode() Will Make Everything Worse!!
When Checking For Array Length: NullReferenceException
When Clamping An Index Value Between 0 And Array.Length: NullReferenceException
When Clicking Something: NullReferenceException
Everything: NullReferenceException!!
However, The Error Goes Away When I Edit Or Recompile My Script!!
Here Is An Example Code I Made, Which Is Very Very Simple, But NullReferenceException!!!
-C#:
using UnityEngine;
[ExecuteInEditMode()]
public class TEST : MonoBehaviour
{
public int index = 0;
public MyClass[] myType = null;
[System.Serializable]
public class MyClass
{
public float myVar = 0f;
public int _myVar = 0;
public Transform m_myVar = null;
}
public void Update ()
{
index = (int)Mathf.Clamp(index,0,Mathf.Clamp(myType.Length - 1,0,Mathf.Infinity));
}
}
-JavaScript:
@script ExecuteInEditMode()
public var index : int = 0;
public var myType : MyClass[] = null;
public class MyClass
{
public var myVar : float = 0;
public var _myVar : int = 0;
public var m_myVar : Transform = null;
}
public function Update ()
{
index = Mathf.Clamp(index,0,Mathf.Clamp(myType.Length - 1,0,Mathf.Infinity));
}
Can Someone Help Me With This?? I’ve Been Suffering From This Error For A Long Time!!
Also The Error Points At Clamping Line Which Has myType.Length In It!
However In Some Scripts It Works Well, But In Newer Scripts, NullReferenceException!!!