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
1
Question by Stratosome · Jul 17, 2018 at 10:28 PM · editoreditor-scriptingeditorwindowhierarchyeditorgui

What is the best way to draw icons in Unity's Hierarchy window?

MY QUESTION

What is the most efficient way to draw an icon/image in Unity's Hierarchy window to hopefully minimize the amount that Unity may slow down? I'm currently using EditorGUI.LabelField() with predefined GUIContents that grab an icon using EditorGUIUtility.IconContent().


MY ISSUE

I've recently been working on making my own "skin" for Unity's Hierarchy window. Everything has been fine and was turning out well until I started drawing icons next to objects. Here is what it is at now:

alt text

The problem though is when I draw the icons (on the left), and there are a lot of objects in the Hierarchy window. Unity's editor begins to slow down at this point. Which I get. Drawing a bunch of images like this can be taxing. It is only with the icons though. If I comment out the one line of code that is drawing them, it all runs smooth. I don't like this. I feel like it shouldn't slow down all that much, or there should be a way to draw the icons more efficiently. Here is a little code snippet of how I'm drawing the icons:

 // Grab icon GUIContent from dictionary in HierarchyDefaultConfigSettings
 GUIContent iconGUIContent = HierarchyDefaultConfigSettings.defaultLabelIconMapping[labelDetails.name];
 
 // Make and adjust rect for icon
 Rect iconRect = new Rect(fullSelectionRect);
 iconRect.width = EditorGUIUtility.singleLineHeight;
 iconRect.height = EditorGUIUtility.singleLineHeight;
 iconRect.height -= 2;
 iconRect.y += 1;
 iconRect.x += 1;
 
 // Drawing of icon (CAUSES EDITOR TO SLOW DOWN! :c)
 EditorGUI.LabelField(iconRect, iconGUIContent, ""); 

It's not like I'm creating the GUIContents inside of this main function that is doing the drawing of the labels and such. Also, the main drawing function is attached to the EditorApplication.hierarchyWindowItemOnGUI delegate just for more info.

customhierarchywindow.png (21.2 kB)
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
3
Best Answer

Answer by Stratosome · Jul 18, 2018 at 12:58 AM

Hmm, welp, gonna "answer" my own question here. It seems like this helps greatly:

 EditorGUI.LabelField(iconRect, iconGUIContent);

Just removing the empty string from LabelField made the performance much better while shrinking the icons a bit I guess. Just gotta increase the Rect size to make up for it? I dunno. This works for me for now.

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

127 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

Related Questions

Any way to attach a bit of code to individual UI Windows [Editor] 1 Answer

How do I code my own custom built blend tree node as seen in the Animation Controller Editor Window? 1 Answer

Custom Prfab Editor Window 0 Answers

Custom Editor - Is there any way to detect whether the user is in Prefab editing mode? 1 Answer

Editor Window Views 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