Search Unity

Couldn't find SendMessage function?

Discussion in 'Editor & General Support' started by ArenAK, Apr 20, 2015.

  1. ArenAK

    ArenAK

    Joined:
    Oct 30, 2014
    Posts:
    5
    I'm using Unity5.0. And I'm trying to implement communications between browser and published webgl program.

    Now the problem is I couldn't find SendMessage function. As this page mentioned, there should be a "SendMessage" funciton in UnityConfig.js: http://answers.unity3d.com/questions/825602/browser-to-unity-webgl-communication.html

    However, When I build my project with WebGL, there is a UnityConfig.js, but no SendMessage within it.

    Could anyone please help me?
     
    clintomed likes this.
  2. ArenAK

    ArenAK

    Joined:
    Oct 30, 2014
    Posts:
    5
    Does anyone know how to solve this problem?
     
  3. clintomed

    clintomed

    Joined:
    Jan 10, 2014
    Posts:
    2
    You ever find a fix? Would love to know the answer.

    Edit: Just needed some patience. Everything has to be fully loaded. Here is my sample code from index.html:

    Code (JavaScript):
    1. <input type="button" id="move_up" onclick="moveUp()" value="Move Up" />
    2.     <input type="button" id="move_down" onclick="moveDown()" value="Move Down" />
    3.     <script type='text/javascript'>
    4.   // connect to canvas
    5.  
    6.   function moveUp() {
    7.     SendMessage("Cube", "MoveUp", "Testing");
    8.     console.log("Attempting to Move Up");
    9.   }
    10.  
    11.   function moveDown() {
    12.     SendMessage("Cube", "MoveDown", "Testing");
    13.     console.log("Attempting to Move Down");
    14.   }
     
    Last edited: Jun 10, 2015
  4. azporispo

    azporispo

    Joined:
    Jul 19, 2012
    Posts:
    4
    I was able to call a function from my a gameobject in my scene from my javascript code.

    My scene was loading very slow, even when I only have two gameobjects inside it.
    And because I called my function "SendMessage" before the page finish loading, a pop up with the error "SendMessage is not defined" appears.

    -The steps to solve it were:

    1-The form to call the funtion is :

    function SaySomethingToUnity(_parameter_To_Send)
    {
    SendMessage("GameObject_To_Call", "Function_To_Call", _parameter_To_Send);
    }
    You DO NOT need to use ""u.getUnity()" anymore.
    Remember that (SendMessage will then call the function Function_To_Call() on the game object named GameObject_To_Call, passing a piece of string, int or float, data as an argument)

    2-Disable thee Exceptions in Unity(PlayerSettings->Publishing Settings->Enable Exceptions: None). This form, my scene was loading faster.
    3-When everything was loaded. The "SendMessage" error did not appears anymore (the file UnityConfig.js that Unity generated when building does not have a definition for the function SendMessage, so do not look for it).