Unity 6 WebGL Bug: SendMessage() from JS is broken! (worked in 2022.2) [CASE IN-82457]

What happened:

“unityInstance.SendMessage” doesn’t work when called right after the WebGL player is loaded (inside createUnityInstance().then callback). Console says “SendMessage: object X not found!”

This used to work in 2022.2. A slight delay of 1-5 seconds solves the issue!

Steps to reproduce from scratch:

  1. Create a new Unity 6.0.14f1 URP project

  2. Switch to WebGL Build Target

  3. Add an object called “Main” to the scene

  4. Add a “Test.cs” script with a single “Log()” method that writes to console with Debug.Log(“Log!”)

  5. Add an object called “Main” to the scene and attach the “Test” script to it

  6. Build and Run a WebGL Development Build

  7. In index.html, add “unityInstance.SendMessage(“Main”, “Log”);” right after the Unity is loaded (line 113, inside createUnityInstance().then callback)

  8. Reload the page to apply the patch

Result: console says “SendMessage: object Main not found!”
Expected behavior: console says “Log!”

Note: calling “setTimeout(function() { unityInstance.SendMessage(“Main”, “Log”); }, 5000)” instead works fine! SendMessage will find the object after a short delay.

This worked totally fine and without delays in unity 2022.2! So I can’t upgrade my project because of this.

I’ve submitted a bug report: CASE IN-82457

1 Like