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:
-
Create a new Unity 6.0.14f1 URP project
-
Switch to WebGL Build Target
-
Add an object called “Main” to the scene
-
Add a “Test.cs” script with a single “Log()” method that writes to console with Debug.Log(“Log!”)
-
Add an object called “Main” to the scene and attach the “Test” script to it
-
Build and Run a WebGL Development Build
-
In index.html, add “unityInstance.SendMessage(“Main”, “Log”);” right after the Unity is loaded (line 113, inside createUnityInstance().then callback)
-
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