PropertyDrawer in JS only works when viewed in inspector

Hi, I’ve been using PropertyDrawers to make my scripts a little easier to use for a while now, but I’ve run into a problem.

I have a script, written in UnityScript, which uses an array of PropertyDrawer variables. These variables are supposed to be changed in-script and by manual input both. Everything works just fine if I have the script showing in the inspector, but it starts throwing errors if I click on a different object. I haven’t tried building out the game yet either…

So I guess my first question would be, is this a bug or is this normal? Are PropertyDrawer variables supposed to only update when in the inspector? And if that’s the case, is there some easy fix for it?

If need be, I can post the script here, just let me know if you need to see it.

I’m hoping someone more experienced with this will have an easy fix, I usually use these sparingly as it is…

EDIT: Here’s a snippet of my code for reference and some further explanation:

public class CustomClass{
	var customvar1 : Transform;
	var customvar2 : float;
	var customvar3 : float;
	var visible : boolean;
}

@CustomPropertyDrawer(CustomClass)
public class CustomClassDrawer extends PropertyDrawer {
	public override function OnGUI(position: Rect, property: SerializedProperty, label: GUIContent) {
	EditorGUI.BeginProperty(position, label, property);
	var indent = EditorGUI.indentLevel;
	EditorGUI.indentLevel = 0;

	EditorGUI.LabelField(Rect(position.x, position.y, 50, position.height), "One");
	EditorGUI.LabelField(Rect(position.x + 155, position.y, 50, position.height), "Two");
	EditorGUI.LabelField(Rect(position.x + 250, position.y, 50, position.height), "Three");

	var OneRect = new Rect(position.x + 50, position.y, 100, position.height);
	var TwoRect = new Rect(position.x + 200, position.y, 30, position.height);
	var ThreeRect = new Rect(position.x + 290, position.y, 30, position.height);

	EditorGUI.PropertyField(TwoRect, property.FindPropertyRelative("customvar3"), GUIContent.none);
	EditorGUI.PropertyField(ThreeRect, property.FindPropertyRelative("customvar2"), GUIContent.none);
	EditorGUI.PropertyField(OneRect, property.FindPropertyRelative("customvar1"), GUIContent.none);
	EditorGUI.indentLevel = indent;
	EditorGUI.EndProperty();
	}
}

var CustomList : CustomClass[]; //this is altered from in-script sources and from the inspector...

and here is where I get an issue:

function OnTriggerEnter( other : Collider){
	if(other.tag == thetag){
		var something : boolean = false;
		if(curr > 0){
			for(var forvar : CustomClass in CustomList){
				if(forvar.customvar1 == other.transform){
					forvar.customvar2 = Time.time;
					forvar.visible = true;
					something = true;
				}
			}
		}
		if(something == false){
			print(forvar[curr]);
			forvar[curr].customvar1 = other.transform;
			curr++;
		}
	}
}

on the line with the print function, if I have the object in the inspector window, it prints “CustomClass” which is what I’d expect, but if I’ve got anything else in the inspector instead, it returns as “Null” and I get this error code:

“NullReferenceException: Object reference not set to an instance of an object
MyScript.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/MyScript.js:97)”

any thoughts?

After further troubleshooting and debugging I found my problem to be this:

UnityScript apparently doesn’t create a list of type public class so easily. I had this line in my Start function:

CustomList = new CustomClass[10];

which it turns out needed to be followed by:

CustomList[0] = new CustomClass();

my guess is that while Unity recognizes the class as a type, it doesn’t construct the individual variables within it automatically… This is just a guess so if anyone knows why this really happens feel free to explain.

As this problem turned out to be based mostly on my personal case, I doubt this will help anyone, but I left this explanation just in case.