- Home /
Unity WebGL UnityInstance.SendMessage Error: SendMessage: object Object1 does not have receiver for function moveObject
I have a built WebGL Unity game using Unity 2020.3.8f1 and I have modified the script on the index.html template to look like this: I only changed one line: unityInstance.SendMessage("Object1", "moveObject");
script.onload = () => {
createUnityInstance(canvas, config, (progress) => {
progressBarFull.style.width = 100 * progress + "%";
}).then((unityInstance) => {
loadingBar.style.display = "none";
unityInstance.SendMessage("Object1", "moveObject");
fullscreenButton.onclick = () => {
unityInstance.SetFullscreen(1);
};
}).catch((message) => {
alert(message);
});
};
When the line gets called, it just returns with an error:
SendMessage: object Object1 does not have receiver for function moveObject!
I did check to make sure that Object1 does have a moveObject function which does not have any parameters. It may help to mention that the Unity Game Object, Object1, has 2 scripts attached and I am not sure if the sendmessage function does not know where to get the function from. Is there away to also define which script you want to call the function of? ,I have a built WebGL game in which I am editing the index.html template and modified only this part and added unityInstance.SendMessage("Object1", "moveObject");:
script.onload = () => {
createUnityInstance(canvas, config, (progress) => {
progressBarFull.style.width = 100 * progress + "%";
}).then((unityInstance) => {
loadingBar.style.display = "none";
unityInstance.SendMessage("Object1", "moveObject");
fullscreenButton.onclick = () => {
unityInstance.SetFullscreen(1);
};
}).catch((message) => {
alert(message);
});
};
When the function gets called, it just prints an error in the console:
SendMessage: object Object1 does not have receiver for function moveObject!
One thing to mention is that Object1 has 2 scripts "attached" and I am not sure if the sendMessage does not know which of the two functions to call the function in. I made sure that Object1 does in fact include the moveObject function which doesn't have any parameters.