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 wmadwand · Sep 01, 2017 at 08:23 AM · 2duiguiinterfacepresets

Bad result of changing RectTransform values (Anchor Preset) programmatically

Howdy, guys! I change RectTransform values of the GO with Image component programmatically. Kinda choose the Anchor Preset but from the code. And as a result i get GO with Image in the right place (according to the anchor's values) but sprite of the Image in the wrong (previous) place.

Screenshot:

alt text

Piece of code:

 switch (_tutorialPage.tooltipPosition)
             {
                 case TooltipPosition.RightBottom:
                     {
                         _tooltipPanelRect.anchorMin = new Vector2(1, 0);
                         _tooltipPanelRect.anchorMax = new Vector2(1, 0);
                         _tooltipPanelRect.pivot = new Vector2(1f, 0f);
                         _tooltipPanelRect.anchoredPosition = new Vector2(0, 0);
 
                         _tooltipGuideRect.anchorMin = new Vector2(1f, 0);
                         _tooltipGuideRect.anchorMax = new Vector2(1f, 0);
                         _tooltipGuideRect.anchoredPosition = new Vector2(-188, 125);
                         break;
                     }
                 case TooltipPosition.LeftBottom:
                     {
                         _tooltipPanelRect.anchorMin = new Vector2(0, 0);
                         _tooltipPanelRect.anchorMax = new Vector2(0, 0);
                         _tooltipPanelRect.pivot = new Vector2(1f, 0f);
                         _tooltipPanelRect.anchoredPosition = new Vector2(_tooltipPanelRect.rect.width, 0);
 
                         _tooltipGuideRect.anchorMin = new Vector2(1f, 0);
                         _tooltipGuideRect.anchorMax = new Vector2(1f, 0);
                         _tooltipGuideRect.anchoredPosition = new Vector2(244, 125);
                         break;
                     }
                 case TooltipPosition.CenterBottom:
                     {
                         _tooltipPanelRect.anchorMin = new Vector2(0.5f, 0);
                         _tooltipPanelRect.anchorMax = new Vector2(0.5f, 0);
                         _tooltipPanelRect.pivot = new Vector2(1f, 0f);
                         _tooltipPanelRect.anchoredPosition = new Vector2(_tooltipPanelRect.rect.width / 2, 0);
 
                         _tooltipGuideRect.anchorMin = new Vector2(0.5f, 0);
                         _tooltipGuideRect.anchorMax = new Vector2(0.5f, 0);
                         _tooltipGuideRect.anchoredPosition = new Vector2(_tooltipGuideRect.rect.width / 2, 125);
                         break;
                     }
             }

Next, after choosing whichever different Anchor Preset manually things get right and the sprite changes the position to the right place similar with the Image.

Does anybody know how to deal with it?

i80cimgpsh-orig222222.png (198.0 kB)
Comment
Add comment · Show 1
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 wmadwand · Sep 02, 2017 at 05:52 AM 0
Share

Guys @Homeship, @alejandro-unity , @crazy$$anonymous$$night may be you have any ideas how to sort it out?

1 Reply

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

Answer by wmadwand · Sep 02, 2017 at 12:24 PM

Finally got the solution:

 *Piece of code from the above*
 
 CanvasGO.SetActive(false);
 CanvasGO.SetActive(true);

And that's all the trick. Simple but slightly inefficient, thought.

And here's another one option which i haven't tried yet but pathetically the better one due to its better performance:

 IEnumerator UpdateUIPanel()
 {
    *Piece of code from the above*
    yield return null;
    Canvas.ForceUpdateCanvases();
 }

And yep, it definitely looks like Unity bug.

Comment
Add comment · Show 2 · 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 slik · Sep 04, 2017 at 09:50 AM 0
Share

Did you try https://docs.unity3d.com/ScriptReference/UI.LayoutRebuilder.ForceRebuildLayoutImmediate.html ?

avatar image wmadwand slik · Sep 22, 2017 at 10:58 AM 0
Share

Will defenitely try this one. Thanks for the answer!

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

190 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

Related Questions

Converting OnGUI function to UI 1 Answer

Health Bar Percentages Problem 2 Answers

Interface relative scaling 0 Answers

Not sure where to start... Riichi Mahjong game 0 Answers

Problem with GUI element following enemy 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