Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

SendMessage on onRuntimeInitialized

Discussion in 'WebGL' started by senghoff, Aug 6, 2019.

  1. senghoff

    senghoff

    Joined:
    Feb 11, 2017
    Posts:
    9
    I am on Unity 2018.4.4f1 with WebGL as target.

    I am attempting to perform a SendMessage by JS from the embedding HTML to a scene object when the WebGL app has completed initialisation. The SendMessage call is done in the onRuntimeInitialized callback as follows -

    Code (JavaScript):
    1.        var gameInstance = UnityLoader.instantiate("gameContainer", "Build/Spinner Winner.json",  {
    2.         Module: {
    3.           onRuntimeInitialized: function () {
    4.             gameInstance.SendMessage("TestURL", "URL", "Test URL");
    5.           }
    6.         }
    7.       });
    8.  
    UnityLoader.js consistently throws an exception on the SendMessage. The wording of the message differs slightly between browsers. In Chrome (attached screenshot) the message is "Uncaught RuntimeError: memory access out of bounds".

    Any help in resolving this issue would be greatly appreciated :)
     

    Attached Files:

  2. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    288
    onRuntimeInitialized is called when the WebGL/WASM/ASM.JS is loaded, not when the first scene is loaded.

    It'll be much safer for you to notify from your Unity scene/script to the page, that now it's ok to call to functions in your project
     
    doctorpangloss and Logic_Bomb like this.
  3. Hao-Cheng-Lee

    Hao-Cheng-Lee

    Joined:
    Nov 28, 2016
    Posts:
    5
    I don't understand what's your mean with the safer call in Unity scene/script. Sends data to a scene from the WebGL Template is necessary for me, so where can I call it if that not safe.
     
  4. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    288
    When the scene loads, call from unity to the page and notify it that now it's ok to send data to the scene...