[Unity 2020.1] About unityInstance not beeing global anymore

Hello,

We can see in the documentation that to call a C# methode from jslib, we have to use “unityInstance.SendMessage(…)”.
But since 2020.1, “unityInstance” is not declared as global by default in the “index.html”, so after each build, i have to tweak the “index.html” file before i can actually test my application.

Is there a way to call “unityInstance” inside the jslib without having to make it global in the “index.html” file ?

Thanks for your help :slight_smile:

I’ve found that the default template is located in C:\Program Files\Unity\Hub\Editor\2020.1.0f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\WebGLTemplates\Default\index.html.

So this solved my “tweaking file after each build” thing.
But still i would like to do a Module that would work seemlessly with Webgl/Standalone/etc, and now if someone whant to use it, he will have to remember to tweak the file after each Webgl build, or create a new template just for this specific module to work.

And having access to the unityInstance seems very usefull, i dont understand why it have been removed from the default template ? This is causing a lot of webgl asset to fail in the asset store too.

So still if i could at list access this unityInstance in the jslib somehow, without having to change the template, that would be great if anyone know :slight_smile:

Thx again ^^

see.

Yep i already saw that, but i believe it gives no hints to how we can access the unityInstance inside the jslib without having to tweak the index.html in the default template (or after each build).

finally, i copy the default template and :
.then((ui) => {
unityInstance = ui;

and outside ,
function getUnityInstance() {
return $(“#iframe_unity_id”)[0].contentWindow.unityInstance;
}
Actually, i want honw how to touch unityInstance directly without use template too :smile:

at least it works :wink:

Yep, its sad to loose the default global unityInstance, but the worst thing is having to tweak the index.html just so we can use the unityInstance inside the jslib :frowning:
I have no knowledge about the technologies involved but i feel that they must be a work around, witch is why im posting here in the first place ^^

The code of the jslib is inside the unityInstance.Module.
So inside the jslib you can just call Module.SendMessage…

Yes it works !
I saw you post about this where you talked about “Module.UnityInstance”, but it didn’t work and when i did inspect the Module variable i though it was null so i did not investigate more. That was a mistake obviously.
I don’t have so much time to see how all of this works right now so this is helping me a lot !
Thank you :slight_smile:

You can open the Chrome or Firefox dev tools and print the content of unityInstance after it loads, you’ll be able to inspect all the methods/variables of it.

console.log(unityInstance)