• 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 t-heo · Jan 17, 2020 at 09:15 AM · listoptimizationchild objectdropdown

Poor performance with adding List to Dropdown

Hi!

I am having an issue with extremely poor performance when making a list of child components that are displayed in TMP Dropdown. The list is huge (+5000 children) but even with 500 it is not much better.

I have a seen an architectural mobile app that did just the same with even a greater list of child objects so I am certain it is my poor technical execution and not a technical limitation of Unity. I don't need to form a list of anything else but the name of the child.

Here's the execution:

 List names = new List() {"test"};

 public TMP_Dropdown dropdown;
 public GameObject ImportedModel;
 
 private string rename;
 void Start()
 {
     var list0 = ImportedModel.GetComponentsInChildren(typeof(Component));
     for (int i0 = 3; i0 < list0.Length; i0++)
     {
         rename = list0[i0].name;
         names.Add(rename.ToString());
 }



I would appreciate tips on how to optimize performance to make this work, for example whether I should use something other than a List. The child objects also exist in an XLM. document so they could be read from a file and not inside the program from an object.

EDIT: The issue is not with collection of children components but applying a list formed of them to TMP Dropdown.

Comment
Add comment · Show 18
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 ShadyProductions · Jan 17, 2020 at 10:58 AM 0
Share

What action exactly is giving poor performance?

The script seems fine, although you could add a stopwatch on the Imported$$anonymous$$odel.GetComponentsInChildren(typeof(Component)); call and see how long it takes, but I don't think it should be that bad.

Need some more information, it could also help to take a look at the unity profiler.

Show more comments
avatar image Bonfire-Boy · Jan 17, 2020 at 11:26 AM 0
Share

I don't suppose this'll make a difference that makes a difference but the redundant function call in rename.ToString() niggles me. I guess maybe it gets compiled out.

avatar image Bonfire-Boy · Jan 17, 2020 at 11:29 AM 0
Share

Also do you need to initial the List before the Start function? If not then you could gain a bit by only creating it once you know how big it'll be, setting the capacity at that point. That should speed up the Adds a little.

avatar image antonsem · Jan 17, 2020 at 11:54 AM 1
Share

I'm not sure that it can be optimized too much, it is a lot of components you are talking about. But as @ShadyProductions suggested ti$$anonymous$$g each part might help to deter$$anonymous$$e the exact cause for the performance loss. That being said, there are a couple of tweaks you can implement, but I don't think they will help you much. 1. Cache the children number 2. Create a new list with that capacity 3. Use the cached number to iterate 4. Don't use ToString(), it looks redundant anyway

So the final code will look like this:

      List<string> names;
      public T$$anonymous$$P_Dropdown dropdown;
      public GameObject Imported$$anonymous$$odel;
      
      void Start()
      {
          var list0 = Imported$$anonymous$$odel.GetComponentsInChildren(typeof(Component));
          int count = list0.Length;
          names = new List<string>(count);
          for (int i0 = 3; i0 < count; i0++)
          {
              names.Add(list0[i0].name);
          }
      }
avatar image t-heo · Jan 17, 2020 at 12:16 PM 0
Share

$$anonymous$$any thanks for the comments. I implemented antonsem's script.

Unfortunately performance is still extremely poor. I think this related to T$$anonymous$$P_Dropdown; I can debug log the names of the +5000 components without an issue but when they are added to T$$anonymous$$P_Dropdown ( dropdown.AddOptions(names); - that I added after the for loop).

The performance is so bad it takes $$anonymous$$utes just to stop running the program.

EDIT: For some reason, every name is applied to three times to the list. So if part1 is one child, it is listed three times in the Dropdown. I tested performance when listing only last 500 children. Then performance is acceptable but it gradually decreases the more children are listed in Dropdown. I use dropdown.AddOptions(names); at the end of Start after the loop.

Show more comments

1 Reply

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

Answer by t-heo · Jan 17, 2020 at 01:40 PM

@Bonfire-Boy provided an answer; I was wrongly referencing components where I just wanted the child's name, hence tripling the amount of list items. It now works, although TMP Dropdown performance is quite poor on AR / Mobile when it has many options.

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

128 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

Related Questions

A node in a childnode? 1 Answer

Variable Scroll How do I make it Scroll 1 Answer

How can i find the world Position from a Child Object in a List? 0 Answers

Best way to add specific child objects to a list. 1 Answer

Question about variabl lists 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