question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Regression in 8.x: canvas size no longer adjusts with available space

See original GitHub issue

Describe the bug We’re trying to move to an Unity 2020.1 build. Therefore I upgraded to v8.x and made the necessary changes to the application.

One of our Unity components is wrapped together with another (optional) div in a parent that covers the whole window. The 2nd div is rendered dynamically based on its React component visibility state (think of a side-bar pop-up window), i.e. roughly this structure:

<div
  style={{
    display: 'flex',
    flexDirection: 'row',
    height: '100%',
    width: '100%',
  }}
>
  <Unity unityContext={...} width="100%" height="100%" />
  {<div .... > .... some content ... </div>} // or "null" when invisible...
</div>
  • 2nd div not rendered: resizing the browser works nicely, i.e. the Unity canvas always resizes to the available space
  • 2nd div rendered: canvas width does not change
    • i.e. the browser renders a horizontal scroll bar and both elements are rendered side-by-side
    • this forces the user to scroll to the right to make the contents of the 2nd div visible.
    • in the example I’m looking at I see in the browser element inspector <canvas width="1272" ... >
    • if I now change the the width in the inspector manually to some value between 0 to 820 then the canvas recalculates to width="821", which is apparently the correct size to display the canvas and the 2nd div without a horizontal scroll bar
    • when I close the 2nd div again, the canvas recalculates again to width="1272" and thus fills the width of the window again
    • as far as I can tell only the case of shrinking the canvas width automatically isn’t working

Expected behavior Unity canvas should resize to available space in the parent

Desktop (please complete the following information):

  • OS: Fedora 32
  • Browser: Chromium 84

Additional context This worked without problems for the same web app/Unity components using an Unity 2019 build and 7.x.

I first thought that this might be caused that the enabling of the 2nd div doesn’t trigger a re-render of the Unity component. But even after changing the code to ensure a re-render, the canvas size is not adjusted. I think this is because there are no prop changes as the width/height are hard-coded to 100%, i.e. either React or react-unity-webgl doesn’t consider this a “component has been updated” case.

  • I also tried <Unity width="auto" ... > but then the canvas no longer resizes when I make the browser window wider. It stays at the original width and the right hand side of the browser window is a blank white space.
  • <Unity width="-webkit-fill-available" ... > seems to behave like the 100% variant.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
stefanb2commented, Sep 1, 2020

BTW: such an upgrade page might also be the right place to mention that the resized event has been removed.

0reactions
jeffreylanterscommented, Sep 1, 2020

Thank you. I’ve updated the documentation

Read more comments on GitHub >

github_iconTop Results From Across the Web

Maximum size of a <canvas> element - Stack Overflow
The maximum size for a canvas element is 3 megapixels for devices with less than 256 MB RAM and 5 megapixels for devices...
Read more >
Responsive canvas size · Issue #47 · jeffreylanters/react-unity ...
The width and height of the canvas will not change, they are fixed to the initial size. using JS, to adjust canvas' width...
Read more >
Large canvas size | FAQs and known issues - Adobe Support
Creating artwork on a large canvas? Learn about common questions, known issues, and troubleshooting tips.
Read more >
Linear Regression - UCI Canvas
This chapter is about linear regression, a very simple approach for supervised learning. In particular, linear regression is a useful tool for pre-....
Read more >
50. Enlarging the canvas with Canvas Size
"Change Canvas Size" command in Canvas tool lets you change the size of the canvas. Open ① the Tool Selection windowand select ②...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found