The question is answered, right answer was accepted
Index Out OF Range Exception
It's strange few days ago everything was running fine now i getting 2 IndexOutOFRange Exception errors. Does anyone have any ideas how to fix this ....
using UnityEngine; using System.Collections; using UnityEditor;
[CustomEditor(typeof(SpawningMachyne))] public class SpawnEditor : Editor { public override void OnInspectorGUI() { SpawningMachyne SM = target as SpawningMachyne;
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Script"));
SerializedProperty ob = serializedObject.FindProperty("holder");
EditorGUILayout.PropertyField(ob);
if(ob.isExpanded)
{
EditorGUI.indentLevel += 1;
EditorGUILayout.PropertyField(ob.FindPropertyRelative("Array.size"));
for (int i=0; i < ob.arraySize; i++ )
{
SerializedProperty el = ob.GetArrayElementAtIndex(i);
EditorGUILayout.PropertyField(el);
if (el.isExpanded)
{
EditorGUI.indentLevel += 1;
EditorGUILayout.PropertyField(el.FindPropertyRelative("go"));
switch (DoShipChecking(SM, i))
{
case 0: break;
case 1:
GUILayout.Space(10);
GUILayout.BeginVertical("box");
EditorGUILayout.LabelField("Eship1");
GUILayout.Space(5);
EditorGUILayout.PropertyField(el.FindPropertyRelative("flypoints"), true);
EditorGUILayout.PropertyField(el.FindPropertyRelative("onfinish"), true);
GUILayout.EndVertical();
GUILayout.Space(10);
break;
case 4:
GUILayout.Space(10);
GUILayout.BeginVertical("box");
EditorGUILayout.LabelField("Eship4");
GUILayout.Space(5);
EditorGUILayout.PropertyField(el.FindPropertyRelative("flypoints"), true);
EditorGUILayout.PropertyField(el.FindPropertyRelative("onfinish"), true);
GUILayout.EndVertical();
GUILayout.Space(10);
break;
}
EditorGUILayout.PropertyField(el.FindPropertyRelative("Start_Wait"));
EditorGUILayout.PropertyField(el.FindPropertyRelative("Spawn_Wait"));
EditorGUILayout.PropertyField(el.FindPropertyRelative("Count"));
EditorGUILayout.PropertyField(el.FindPropertyRelative("spawntype"));
if (SM.holder[i].spawntype == SpawnType.Random) **// exception error Here**
{
EditorGUILayout.PropertyField(el.FindPropertyRelative("randomdir"));
}
EditorGUILayout.PropertyField(el.FindPropertyRelative("Spawn_Pos"));
EditorGUI.indentLevel -= 1;
}
}
EditorGUI.indentLevel -= 1;
}
//EditorGUILayout.PropertyField(serializedObject.FindProperty("objects"), true);
if (EditorGUI.EndChangeCheck())
serializedObject.ApplyModifiedProperties();
}
int DoShipChecking(SpawningMachyne SM, int i)
{
if (SM.holder[i].go.GetComponent<E_Ship_1>() != null) **// and another Here**
return 1;
if (SM.holder[i].go.GetComponent<E_Ship_4>() != null)
return 4;
return 0;
}
}
Answer by Oziry · Dec 27, 2016 at 12:22 PM
//soliution is to use this to update array making shiure it initiated
if (EditorGUI.EndChangeCheck())
serializedObject.ApplyModifiedProperties();
EditorGUI.BeginChangeCheck();
// and use this to bypas emty game objects
if (SM.holder[i].ship)
{
//stuff to do if initiated
}
Follow this Question
Related Questions
error CS0118 'charanim.CameraTurn' is a field but a 'type' was 'expected' 1 Answer
Unity Unet spawnig Fail,Unity Unet NetworkManager spawning fail 1 Answer
Webplayer: Catch "Failed to download data file" error 0 Answers
Append log error message 0 Answers
What does this error message mean and how do I fix it? 1 Answer