• 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
0
Question by Potaski · Jun 26, 2014 at 04:18 AM · editorarrayinspectorbool

DeletArrayElementAtIndex crashes Unity when operating a bool array

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.

Comment
Add comment · Show 1
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 Potaski · Jun 26, 2014 at 04:50 AM 0
Share

edit: I changed the "isSkipped" property to int type and it works. I think it's a bug.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by cfloutier · Apr 26, 2015 at 02:38 PM

i've got the same issue on unity 5

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How can I recreate the Array Inspector element for a custom Inspector GUI? 7 Answers

Acessing array / list from Gizmos in editor 1 Answer

Is it possible to drag/drop/increment into editor array? 1 Answer

Unity inspector scripting - scriptable objects - card game 0 Answers

Insert new custom class element with _default_ values to a SerializedProperty array? 1 Answer


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