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 /
  • Help Room /
avatar image
0
Question by kayraucklnc · Jun 24, 2021 at 01:47 PM · editoreditor-scriptingserializedproperty

How to iterate over Serialized List?

Currently what I am doing this but it doesnt work, it prints the correct size of the serialized array but not the content, how can I do it?

                 Debug.Log("Size: " + l.serializedProperty.GetArrayElementAtIndex(l.index).FindPropertyRelative("down").arraySize);
                 for (int i = 0; i < l.serializedProperty.GetArrayElementAtIndex(l.index).FindPropertyRelative("down").arraySize; i++) {
                     Debug.Log(l.serializedProperty.GetArrayElementAtIndex(l.index).FindPropertyRelative("down").GetArrayElementAtIndex(i));
                 }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by oscarAbraham · Jun 25, 2021 at 05:50 PM

It depends on what's inside "down". GetArrayElementAtIndex just returns another SerializedProperty, so you need to access what's inside that SerializedProperty to print it. Suppose down is a a List of GameObjects: public List<GameObject> down;, you could do it like this:

 SerializedProperty downProperty = l.serializedProperty.GetArrayElementAtIndex(l.index).FindPropertyRelative("down");
 Debug.log(downProperty.arraySize);
 for (int i = 0; i < downProperty.arraySize; i++;)
 {
     Debug.Log(downProperty.GetArrayElementAtIndex(i).objectReferenceValue);
 }


You can find how to get the value of different types of properties in this doc page. All the members that have the word "value" in them serve to access different types of data. Although, if down is an array of custom structs or classes, you'll need to do a bit more than that.

Comment
Add comment · Show 4 · 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 kayraucklnc · Jun 25, 2021 at 07:18 PM 0
Share

It is actually a List<GameObject> , I am currently using objectReferance as GameObject is it the best practice?

avatar image oscarAbraham kayraucklnc · Jun 26, 2021 at 12:10 AM 0
Share

@kayraucklnc Yeah, it's perfectly fine; that's what everyone does. I modified the answer's example to make down a list of GameObjects. Does it work for you?

EDIT: Well, it's not objectReference; it's objectReferenceValue.

avatar image oscarAbraham kayraucklnc · Jun 26, 2021 at 04:14 PM 0
Share

Hi, Uhm. If it works for you, could you mark my answer as correct? If it doesn't, could you share some of the class being serialized? That would give me a better idea of what isn't working. Either way, I'd appreciate some feedback or resolution, as it helps other people finding this question in the future, and it helps me to measure the productiveness of my time.

avatar image kayraucklnc oscarAbraham · Jun 26, 2021 at 04:16 PM 0
Share

It totally worked! Thank you, one more follow-up question, sometimes I cast with as GameObject but since it is actually a null value It gives me an error what's the best way to avoid this? Should I use try-catch?

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

211 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 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 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 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 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 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 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 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

Custom Editors - Array of Custom Classes 2 Answers

[Simple question] Adding a new SerializedProperty to a SerializedObject 1 Answer

Unity5-serializedObject.FindProperty("listname") for ReorderableList doesn't work... 2 Answers

Applying values from an animationClip to bones of a skinnedMesh via code? 0 Answers

How is my waypoint line going back to the gameobject it is stored in and not to the waypoint 0 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