Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
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.

avatar image t-heo ShadyProductions · Jan 17, 2020 at 11:20 AM 0
Share

Thanks for your reply. It is indeed a bit puzzling. I think the issue is with T$$anonymous$$P_Dropdown itself, as I can run the for loop in another connection, searching for child components with great performance. I'll have a deeper look on profiler, although I already quickly checked it but could not find the issue.

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.

avatar image Bonfire-Boy t-heo · Jan 17, 2020 at 12:24 PM 1
Share

Have converted answer to comment as it seems pretty clear we don't have an answer yet!

avatar image Bonfire-Boy t-heo · Jan 17, 2020 at 12:27 PM 0
Share

So are you saying that performance of the code as shown is not actually poor? That it's only when you add the list to the dropdown that it goes slow?

If so then then you ought to tweak the question and title to reflect this because as things stand it appears to be about constructing the list.

avatar image t-heo Bonfire-Boy · Jan 17, 2020 at 12:33 PM 0
Share

Title updated to reflect this since the issue turned out to be with T$$anonymous$$P_Dropdown.

avatar image Bonfire-Boy t-heo · Jan 17, 2020 at 12:39 PM 1
Share

Ah, so what were you expecting the list of names to contain?

Component.name gives you the name of the GameObject the component is on. So yeah, you'll get plenty of duplicates. Try logging the components' types using GetType() along with their names, and you'll see what I mean. Even the Transforms will cause the gameObject's name to be added to the list. $$anonymous$$aybe it's the types that you were after?

avatar image t-heo Bonfire-Boy · Jan 17, 2020 at 12:45 PM 0
Share

Basically, I would just need the components name as String. What I am trying to achieve is that every component name is available in a list. Then the user can select one of them from Dropdown menu, and then that child object is highlighted. I would just need its name in a String, so I can run a search function that finds that one part when its selected from Dropdown.

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.

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

Question about variabl lists 1 Answer

Add game building items to dropdown list? 1 Answer

How to make a combo box 4 Answers

Create Enumeration from List 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