Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 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 qwert024 · Mar 04 at 11:33 AM · uicanvaswebgluitoolkitcss

In WebGL, is it possible to make UI Coordinate scale with CSS style?

Hello,
I am using Unity 2021.1.28, built to WebGL.

What I was trying to do, is to (A) force the render resolution of my WebGL build to be 1280x720, while (B) scaling it to be displayed fullscreen in the browser window. In the html file, I tried to use canvas DOM attributes width/height to do (A) and css style width/height to do (B) alt text
And this is the result: https://youtu.be/zRtoAdZ7mtQ

I wrote a script that prints Screen.width and Screen.height with onGUI(). As you can see in the video, the resolution is fixed at 1280x720, and it is forced to be fullscreen in the browser, which is what I want. (It's stretched and looks blurry, but this is ok in my use case) However, it seems that the UI coordinate is fixed at 1280x720 as well. And it isn't scaling with the browser window. Thus I can't click on the UI correctly and the mouse hover effect doesn't look right.
Neither UGUI nor UI Toolkit works.

I was wondering is it possible to make UI Coordinate scale with CSS style? It would be so great if anyone could shed some light!

screenshot-2022-03-04-173146.png (14.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 Whitewalkergp · Mar 04 at 01:06 PM

Hey! I had A LOT of problems with fixing UI for WebGL and it took me days to figure out a way to scale UI properly for WebGL. I'm gonna share what it did to fix my UI scaling and hope it works for you: 1-go to Project settings=>Player=>Resolution and Presentation . and then set your default width and height. 2- Make 3 canvases like this picture alt text

UI UI2 and UI3

For UI canvas do this : in Canvas Scaler put UI Scale Mode to Scale With Screen Size and then set your reference resolution. Screen Match mode on "Match with width or height" and then pull scroll all the way to the right ( height).

For UI2 make sure that the Canvas's anchor is in the middle.

for UI3 : add a "Aspect ratio Fitter" to the UI3 and then put aspect mode on "fit in parent" and then in aspect ratio put whatever aspect ratio you have.

also make sure in game tab your aspect ratio is fixed and then for adding other ui elements make sure that their canvas is the child of Ui3 (for example take a look at sub canvases here : back Lock1 Lock2. this completely fixed my UI problem in web gl. hope it helps you as well.


question-ui.jpg (11.6 kB)
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

241 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

WebGL UI cropped on windowed mode 0 Answers

UI Only Updates As Intended When Editing Through Scene 0 Answers

Screen Space - Camera to Screen Space - Overlay switch issue 0 Answers

How do I get more freedom with positioning UI Text? 1 Answer

How do I mask out part of canvas panel?,How can I mask out part of a canvas panel? 4 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