Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Andrii · Sep 13, 2020 at 08:11 PM · editor-scriptingeditorguieditorguilayout

GUIStyle doesn't work when renamed. What to do here?

I'm fighting with this thing all day and here's what I ended up with. I guess it may be a bug in Unity 2020.1.0f1 but I didn't test it in other versions except for 2018.1.9f2 and it works properly there.

Here are steps to reproduce this. In editor script, OnInspectorGUI() do this:

 //This works just fine
 GUILayout.Button(new GUIContent("Hello one"),GUI.skin.GetStyle("Button"));
 
 //Copyting the button style
 GUIStyle buttonStyle=new GUIStyle(GUI.skin.GetStyle("Button"));
 
 //Changing its name to anything except Button, ButtonLeft, ButtonMid, ButtonRight
 buttonStyle.name="MyButton";
 
 //Same button as above but using my style with changed name
 GUILayout.Button(new GUIContent("Hello two"),buttonStyle);


Here's how it renders:

alt text
What I'm trying to do is I want to create custom styles for GUILayout.Toolbar based on Button style, which seems to be really hard already. And what I came up with works in older Unity but it doesn't in 2020. So I narrowed it to this case where changing the name somehow invalidates the style.


UPD. Found another weird thing about this. If I apply buttonStyle to another button before renaming the style, it will work even after renaming. So it somehow matters if the style was used in UI before it was renamed. Maybe its name gets registered somewhere. But how can I do this without using the style to draw the buttons I don't need?


UPD2. Oh no! Another amazing development! I can't believe my eyes. I have to share this with someone.alt text Looks like the element with non-renamed style has to be visible on screen. As soon as it's out of the view, the element with renamed style looses the style. How am I supposed to beat this? I really want to use those renamed styles. Which hoops should I jump through?


UPD3. It feels like style's name has to be registered somewhere. Like there's some cache that needs to be updated with newly added names. Because you can rename style to existing style names but can't rename to something custom.

gif-2020-09-13-23-39-04.gif (255.8 kB)
screenshot-2.png (1.7 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
0

Answer by Bunny83 · Sep 14, 2020 at 02:11 AM

Where and when do you create your custom style? GUIStyles are actually native objects (at least they have a native counter part). Do you create the styles once, or do you recreate them every time?


So make sure you create your styles once and cache them properly. Depending on what you're doing you may want to consider to create a custom GUISkin


Note that I haven't used the IMGUI system recently. However since they developed the UIElements it seems they gradually replace a lot of the old IMGUI things with optimised UIElements behind the scenes. So your scrollview might just cut off everything that went out of the view.


The source of the IMGUI system is over here. However keep in mind that the lowlevel parts are implemented on the native C++ side. Changing the name does in fact change the rawname on the native side which could cause issues on the native side. If that's really the case I would consider it as a bug. However you should first check if the issue persists when you properly create your style once and cache it.


It would help to have your actual code available to investigate this issue.

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

146 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

Related Questions

Setting custom amount of space between elements in a custom inspector with EditorGUILayout ? 1 Answer

Is it possible to store and display EditorGUILayout.Toggles? 0 Answers

Editor GUI TEXT On Inspector: How to add header text note in the inspector using a Custom Editor Inspector script ? 1 Answer

Custom Inspector and ExposedRefreces 1 Answer

EditorGUI, EditorGUILayout, GUI, GUILayout... pshhh... WHEN TO USE WHAT?! 3 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