Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by thrmotta · Dec 09, 2014 at 07:31 PM · serializationserializedpropertycustomeditorpropertyfieldcaneditmultipleobjects

Invalid iteration - (You need to stop calling Next when it returns false)

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[i];
                 }
             }
            
             EditorGUILayout.Space ();
            
             EditorGUI.indentLevel++;
            
             for( int i = 0; i < nInfo; i++ )
             {
                 if( chosenFunctionsContains( _infoNames[i] ) )
                 {                   
                     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<LinkActuator>();
                         Link linkScript = currLA.gameObject.GetComponent<Link>();
                         for( int i = 0; i < nInfo; i++ )
                         {
                             if( chosenFunctionsContains( _infoNames[i] ) )
                             {
                                 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!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image taxvi · Dec 09, 2014 at 08:06 PM 0
Share

I have little idea about serialization but I suspect the cause of the error is the foreach loop line 106

btw, what is the 'targets'? (maybe very noobish from me, tho)

avatar image thrmotta · Dec 09, 2014 at 11:17 PM 0
Share

targets are all the gameobjets currently selected at the hierarchy. I usually use it when working with simultaneous multiple edition (with the CanEdit$$anonymous$$ultipleObjects tag)

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by thrmotta · Dec 10, 2014 at 12:58 PM

I still do not fully understand why is it working now, but after commenting out all the [HideInInspector] tags, the error vanished!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image taxvi · Dec 10, 2014 at 01:03 PM 0
Share

thanks for sharing

avatar image
0

Answer by tgouala-wellfiredLtd · Jan 26, 2016 at 12:28 PM

Not sure if it is an expected behaviour in Unity, but this seems to occur only with Vector3 and Vector2. If you still need to keep [HideInInspector] on your variable, you can use :

 serializedObject.FindProperty("myVector").vector3Value = EditorGUILayout.Vector3Field(new GUIContent("aVector"), serializedObject.FindProperty("myVector").vector3Value);

Instead of :

 EditorGUILayout.PropertyField(serializedObject.FindProperty("myVector"), new GUIContent("aVector"), false);
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Nesting custom inspectors 0 Answers

Editor Targets are updated but SerializedPropertys arent 1 Answer

Horizontal Scrollbar shows up when Vertical Scrollbar appears 2 Answers

Why are the children of my Serialized Property not being drawn? 1 Answer

Serializing object in scene? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges