Hello!
Ive been getting the following error message:
Invalid iteration - (You need to stop calling Next when it returns false)
Which I can barely find anything about on the internet.
This error occurs when creating a PropertyField on a Custom Editor class.
All the variables used at the PropertyFields (which causes the erros) are Vector3 and are inited on declaration with Vector3.zero. Ive tried to Debug.Log the SerializedProperty vars and all of them are being prited as 0, 0, 0, even when I change them at the Inspector. Actually, because of this error the numbers at the vector3 fields keeps changing every few seconds to random values.
This is the full class which is causing the error (I commented the lines that gives me this error):
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
namespace SimVR
{
[CanEditMultipleObjects, CustomEditor(typeof(FunctionsMask))]
public class FunctionsMaskEditor : Editor
{
private FunctionsMask _script { get { return target as FunctionsMask; }}
int nInfo = 6;
string[] _infoNames = new string[6]{ "Linear Velocity",
"Angular Velocity",
"Linear Acceleration",
"Angular Acceleration",
"Force",
"Torque" };
SerializedProperty _functionsMaskProp;
SerializedProperty _linearVelocityProp;
SerializedProperty _angularVelocityProp;
SerializedProperty _linearAccelerationProp;
SerializedProperty _angularAccelerationProp;
SerializedProperty _forceProp;
SerializedProperty _torqueProp;
SerializedProperty _chosenFunctionsProp;
void OnEnable()
{
_functionsMaskProp = serializedObject.FindProperty("_functionsMask");
_linearVelocityProp = serializedObject.FindProperty("_linearVelocity");
_angularVelocityProp = serializedObject.FindProperty("_angularVelocity");
_linearAccelerationProp = serializedObject.FindProperty("_linearAcceleration");
_angularAccelerationProp = serializedObject.FindProperty("_angularAcceleration");
_forceProp = serializedObject.FindProperty("_force");
_torqueProp = serializedObject.FindProperty("_torque");
_chosenFunctionsProp = serializedObject.FindProperty("_chosenFunctions");
}
public override void OnInspectorGUI ()
{
serializedObject.Update ();
EditorGUILayout.Space ();
EditorGUILayout.Space ();
_chosenFunctionsProp.ClearArray ();
for ( int i = 0; i < _infoNames.Length; i++ )
{
if( (_functionsMaskProp.intValue >> i & 0x1) == 1 )
{
_chosenFunctionsProp.arraySize++;
SerializedProperty elementProperty = _chosenFunctionsProp.GetArrayElementAtIndex( _chosenFunctionsProp.arraySize - 1 );
elementProperty.stringValue = _infoNames*;*
}
}
EditorGUILayout.Space ();
EditorGUI.indentLevel++;
for( int i = 0; i < nInfo; i++ )
{
if( chosenFunctionsContains( _infoNames ) )
{
switch ( i )
{
case 0:
EditorGUILayout.PropertyField( _linearVelocityProp); //Error can happen here
break;
case 1:
EditorGUILayout.PropertyField( _linearAccelerationProp ); //Error can happen here
break;
case 2:
EditorGUILayout.PropertyField( _angularVelocityProp); //Error can happen here
break;
case 3:
EditorGUILayout.PropertyField( _angularAccelerationProp); //Error can happen here
break;
case 4:
EditorGUILayout.PropertyField( _forceProp); //Error can happen here
break;
case 5:
EditorGUILayout.PropertyField( _torqueProp); //Error can happen here
break;
}
}
}
EditorGUI.indentLevel–;
EditorGUILayout.Space ();
if( _chosenFunctionsProp.arraySize > 0 )
{
EditorGUILayout.BeginHorizontal();
GUILayout.Space( 10 );
if( GUILayout.Button ( “Apply” ) )
{
foreach( FunctionsMask currFM in targets )
{
LinkActuator currLA = currFM.GetComponentInParent();
Link linkScript = currLA.gameObject.GetComponent();
for( int i = 0; i < nInfo; i++ )
{
if( chosenFunctionsContains( infoNames ) )
{
if ( i == 0 ) linkScript.ApplyLinearVelocity ( currLA._infoToApply.getInfoToApply( i ) );
else if ( i == 1 ) linkScript.ApplyAngularVelocity ( currLA._infoToApply.getInfoToApply( i ) );
else if ( i == 2 ) linkScript.ApplyLinearAcceleration ( currLA._infoToApply.getInfoToApply( i ) );
else if ( i == 3 ) linkScript.ApplyAngularAcceleration ( currLA._infoToApply.getInfoToApply( i ) );
else if ( i == 4 ) linkScript.ApplyForce ( currLA._infoToApply.getInfoToApply( i ) );
else if ( i == 5 ) linkScript.ApplyTorque ( currLA._infoToApply.getInfoToApply( i ) );
}
}
}_
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space ();
}
serializedObject.ApplyModifiedProperties ();
}
bool chosenFunctionsContains( string name )
{
for ( int i = 0; i < _chosenFunctionsProp.arraySize; i++ )
{
SerializedProperty elementProperty = _chosenFunctionsProp.GetArrayElementAtIndex( i );
if ( name == elementProperty.stringValue )
return true;
}
return false;
}
}
}
What am I doing wrong?
Thank you for your time!