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 nt314p · Aug 14, 2018 at 06:51 PM · canvasscalingenable

Re-enabling canvas causes UI components to lose normal scaling

I have a canvas that has some images, buttons, etc.

It is used as an ending screen, so at the start of the game, it is disabled using the following code:

 endCanvas.enabled = false;

At the end of the game, it is enabled using the same code:

 endCanvas.enabled = true;

The canvas elements are becoming scaled after it is re-enabled.

Before game start (how it is supposed to look) alt text After game end (canvas enabled again, elements scaled) alt text

I found a fix, but I cannot use it.

 endCanvas.gameObject.setActive (false);

And

 endCanvas.gameObject.setActive (true);

I think it has something to do with the UI rebuild that is triggered when onEnable for the gameobject is called, but that's about it.

Thanks, in advance, ~NT

before.jpg (43.0 kB)
after.jpg (34.4 kB)
Comment
Add comment · Show 2
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 hexagonius · Aug 15, 2018 at 07:57 AM 0
Share

are you using Layouting components? if so, disable those after you're satisfied with the layouting result. In some unity versions the layouting is broken.

avatar image eses · Aug 15, 2018 at 09:02 AM 0
Share

@n314p - Do you really need to disable the canvas? How about just make the panel a panel in some other canvas, where all the other UI elements are, and the just disable the panel (if that is possible) ? Or, alternatively make your panel have canvas group, then make it's alpha 0 and interactable false, when the panel is hidden.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by FernandoHC · Aug 15, 2018 at 11:09 AM

The enabled variable is used to activate/deactivate components, in your case, you probably want to deactivate the whole GameObject where that canvas is, so you can actually use gameObject.setActive (true); and gameObject.setActive (false);

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

97 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

Related Questions

Accidentally did 'something' and now positioning is all out of whack (canvas, camera, scaling?) 0 Answers

Background color and structure disappear when enabling GUI Canvas 0 Answers

Using Hinge Joint 2D with scaled UGUI 0 Answers

How to scale the image through scripting so that the height of the image will be equal to the height of the screen and the width of the image will be scaled with the same percentage? 2 Answers

Scene loading incorrectly 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