Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[SOLVED] The "#canvas" width and height are different than the "gameContainer"

Discussion in 'Web' started by OpticalOverride, Aug 3, 2018.

  1. OpticalOverride

    OpticalOverride

    Joined:
    Jan 13, 2013
    Posts:
    161
    EDIT: Solved. Apparently a long time ago in my project I had used a very convoluted way of manually changing the screen resolution in WebGL through this ugly line of code: Display.displays[0].SetRenderingResolution( 320, 320 ); Changed it and all is working now.

    My problem is extraordinarily simple, yet seems to be impossible to fix.

    1) I'm building to WebGL (2017.4.2f2).
    2) I've set the default canvas width and height to 640x640 in the player settings.
    3) I have the Game Window resolution set to the custom 640x640 (the only resolution in the list).
    4) When I build, the <div id="gameContainer"... width and height are both 640.
    5) Inside this div, the <div id="#canvas"... is incorrectly sized with width and height set to 320.

    I previously had 320 as the size (both in the player settings and the resolution for the Game Window), yet I've deleted 320 from everywhere in the settings for the project, yet ONLY #canvas remains at size of 320.

    I can manually change the #canvas width/height to 640 and it works perfectly, until the scene is reloaded in the game (after the player restarts the level), and then, all of a sudden, like out of a horror film and from the depths of some glitched out and unreachable save file referenced by the game scene, #canvas is set back to 320x320.

    My only question after 3 hours of working in circles is, why? Why, oh why...

    Thank you.
     
    Last edited: Aug 3, 2018