Search Unity

"Correct" way to hide and show a loaded WebGL build

Discussion in 'WebGL' started by uwdlg, Mar 7, 2021.

  1. uwdlg

    uwdlg

    Joined:
    Jan 16, 2017
    Posts:
    70
    Hi,

    I would like to mix interactive WebGL content with plain old html elements on a website. Currently, I'm loading a WebGL build once when the site is first loaded and hide and show it as needed via Javascript and CSS, passing in a string to change what's supposed to be displayed. I came up with this because I thought creating a new instance each time would mean waiting for the build to load again and again.
    But I believe just hiding the WebGL canvas via JS & CSS doesn't in any way communicate that the player should stop and resume, meaning it still receives input events (using the new Input System clicks and drags are still registered), continues rendering and calling Update() etc.
    Is there a recommended way to handle situations like this? e.g.
    a) some way to completely halt and resume execution of a Unity WebGL player or
    b) do something similar by hand? (I was thinking about disabling/re-enabling all GameObjects and maybe switch settings like the target framerate between 1 and 30 for example, but that feels wrong and cumbersome).
    Looking forward to any insights, thank you!
     
    Last edited: Mar 12, 2021
  2. uwdlg

    uwdlg

    Joined:
    Jan 16, 2017
    Posts:
    70
    I'm still wondering about this and would love some input
     
unityunity