title: Unity WebGL SendMessage to Unity function error object InGameCanvas/CoilValue not found
body: <p>I've been trying to send a message from a web page using JavaScript to a Unity function but I continue to get a value not found when calling the function.  <em>The object associated is a child object of the canvas so Im not sure that's an issue or not.</em>    Ive tried a combination of things to make it </p>
  
  <p>coilScore is a float and I'm simply passing the number across.</p>
  
  <p><strong>My attempts to reach child object.</strong></p>
  
  <pre><code>gameInstance.SendMessage('CoilValue', 'ReceiveCoilScore', coilScore);[![enter image description here][1]][1]
  gameInstance.SendMessage('InGameCanvas/CoilValue', 'ReceiveCoilScore', coilScore);
  gameInstance.SendMessage('InGameCanvas', 'ReceiveCoilScore', coilScore);
  gameInstance.SendMessage('InGameCanvas.CoilValue', 'ReceiveCoilScore', coilScore);
  
  
  Error: 
  SendMessage: object InGameCanvas/CoilValue not found!  a4527c6b-a81a-4c23-8861-f3553ac675c8:8:48803
  Type: number Total coilScore: 0.000001401 meta_monetization_handler.js:34:10
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/fuage.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fuage.png" alt="JavaScript snippet to call Unity function"></a>
  <a href="https://i.stack.imgur.com/kETkQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kETkQ.png" alt="Unity Function"></a>
  <a href="https://i.stack.imgur.com/NM3dh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NM3dh.png" alt="Game Object Structure"></a></p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Ive added additional information below this line for clarity.</p>
  
  <p>The index.html is calling a .js file.  Inside that .js file I am parsing multiple parameters but the one item I am trying to do is send a message from the .js file to Unity.</p>
  
  <p><strong>index.html</strong>  </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en-us"&gt;
  &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
      &lt;title&gt;Moon Run&lt;/title&gt;
      &lt;link rel="shortcut icon" href="TemplateData/favicon.ico"&gt;
      &lt;link rel="stylesheet" href="TemplateData/style.css"&gt;
      &lt;script src="TemplateData/UnityProgress.javascript"&gt;&lt;/script&gt;
      &lt;script src="Build/UnityLoader.js"&gt;&lt;/script&gt;
      &lt;script&gt;
          var gameInstance = UnityLoader.instantiate("gameContainer", "Build/Moon Run WebGL nonDev.json", {onProgress: UnityProgress});
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div class="webgl-content"&gt;
      &lt;div id="gameContainer" style="width: 1920px; height: 1080px"&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;script src="TemplateData/responsive.javascript"&gt;&lt;/script&gt;
  &lt;script src="meta_monetization_handler.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>meta_monetization_handler.js</strong></p>
  
  <pre><code>   function calcValue(data) {
      return (data.amount * (1 / Math.pow(10, data.assetScale)).toPrecision(data.assetScale)).toPrecision(data.assetScale);
  }
  
  if (typeof document.monetization == "undefined") {
      console.log('document.monetization not found :(');
  } else {
      var info_div = document.querySelector('body &gt; div &gt; div.validator &gt; div');
      var ilp_element = document.getElementById('ilpEnabled');
      var ilp_raw_init_el = document.getElementById('rawInit');
      var cur_pay_el = document.getElementById('currentPaymentAmt');
      var total_estimate_el = document.getElementById('totalEstimateAmt');
      var latest_json_el = document.getElementById('latestJson');
  
      document.monetization.addEventListener('monetizationstart', function(event) {
          info_div.style.backgroundColor = "rgba(63, 65, 68, 0.4)";
          ilp_element.innerHTML = "Interledger Enabled! (Meta-Tag)&lt;br&gt;&lt;br&gt;:)  Thank You!&lt;br&gt;";
          ilp_raw_init_el.innerHTML = JSON.stringify(event.detail, null, 2).replace('{','').replace('}','');
      });
  
      document.monetization.addEventListener('monetizationprogress', function(event) {
          if (typeof this.runningTotal == "undefined") {
              this.runningTotal = 0;
          }
          var monetizationAmount = parseFloat(calcValue(event.detail));
          this.runningTotal += monetizationAmount;
          document.monetization.lastEventPayload = event.detail;
          cur_pay_el.innerHTML = "Latest ILP Payment: $" + monetizationAmount;
          total_estimate_el.innerHTML = "Estimated ILP Total: $" + this.runningTotal.toPrecision(4);
          latest_json_el.innerHTML = "Latest ILP Payment Response: " + JSON.stringify(event.detail);
  
      coilScore = this.runningTotal.toPrecision(4);
      console.log("Type: " + typeof coilScore  + " Total coilScore: " + coilScore );
      gameInstance.SendMessage('CoilValueTextObject', 'ReceiveCoilScore', coilScore);
      });
  }
  </code></pre>