Multiple Instances of WebGL Module

Hello everybody,

I’m a JS developer that interact with several unity devs. We are currently building a backbone.js app that embed a unity webgl module.

From what I am seeing, I discovered that Unity uses a global Module variable and then populates it with x functions.

Here’s the bug :

  • I navigate to my view where the unity module is loaded correctly in a canvas tag
  • I navigate to another page that doesn’t host a Unity module
  • I go back on my first page with the Unity module, and BOOM! It seems that Module loose all his properties, and can’t rebuild/reload the Unity scene (even module)

Here’s the console error :

I kept trying to make it work, I’ve tested that :

  • First time, Unity is loaded correctly with the Module variable set, and the UnityLoader.js loaded (that auto-launch
  • When I exit my page, I save this Module var, and stock it somewhere.
  • When I go back on my Unity page, i relaunch everything with a Module.run(), and BOOM! I’ve got an error “File exists”

Is there anyway to namespace this Module variable ? I think it’s the same trouble that if we wanted to have several webgl modules on the same page.

Thank you for your patience :slight_smile:

Hello JulienVerhaeghe.

What do you mean by going back exactly? Pressing the Back button? (in which case the behavior is correct)

We are already working on this, and this scheme should be available in the future. For now you may just use an iframe for each module displayed on your page, so that they become isolated.

When I speak of going back, it’s just navigating to the page of my webapp that embeds the webgl module. Backbone doesn’t reload the page, it just changes the content of it like an Angular or any JS Framework would do.

I’ll try to make it work with an Iframe, thanks for your reply !

To sum up, my problem is to instanciate a module on a page, destroy it, then be able to run it again. With JS Methods. I know that I’m asking a lot :stuck_out_tongue:

Yes, this is exactly what we are trying to achieve.
However, there are some technical issues that have to be resolved first. For example, having several WebGL modules served from the same document url will cause their PlayerPrefs mixed-up, as at the moment those are specific to the document location. Also, there should be some explicit control over the mouse and keyboard input when multiple modules are instantiated, as the events are document specific. Plus, some user jslib plugins might not respect the namespacing and use global variables instead. It might be not very easy to resolve all this, especially if you intend to host content created by other developers or planning to use 3rd party plugins or libraries.
Considering all this, iframes seem to be quite a good workaround for now.