Hi,
I’ve been working on a custom inspector. Using Add or Remove button to change the size of arrays. When I do this to a Transform array it works fine, but it always crash when used on a bool array. When I restart unity I can see from the inspector that the bool array is turned empty.
Here’s the inspector part of my code:
[CustomEditor(typeof(ClothChain))]
[CanEditMultipleObjects]
public class ClothChainEditor : Editor {
SerializedProperty chainProp;
SerializedProperty skipProp;
void OnEnable () {
chainProp = serializedObject.FindProperty("chain");
skipProp = serializedObject.FindProperty("isSkipped");
}
public override void OnInspectorGUI () {
int i;
int removeId = -1;
for (i=0; i<chainProp.arraySize; i++) {
EditorGUILayout.BeginHorizontal();
if ( GUILayout.Button("-", GUILayout.Width(24)) ) {
removeId = i;
}
if (i<chainProp.arraySize) {
EditorGUILayout.LabelField("Skip", GUILayout.Width(36));
if ( i<skipProp.arraySize ) {
skipProp.GetArrayElementAtIndex(i).boolValue = EditorGUILayout.Toggle (skipProp.GetArrayElementAtIndex(i).boolValue, GUILayout.Width(32));
}
chainProp.GetArrayElementAtIndex(i).objectReferenceValue = EditorGUILayout.ObjectField(chainProp.GetArrayElementAtIndex(i).objectReferenceValue, typeof(Transform), true);
}
EditorGUILayout.EndHorizontal();
}
if ( GUILayout.Button("+", GUILayout.Width(24)) ) {
chainProp.arraySize += 1;
skipProp.arraySize += 1;
}
if (removeId != -1) {
chainProp.DeleteArrayElementAtIndex(removeId); //this line works as expected
skipProp.DeleteArrayElementAtIndex(removeId); //this line will crash unity
}
serializedObject.ApplyModifiedProperties();
}
}
I’m using Unity 4.3.2. is it a bug or am I missing something here.