jeffreylanters / react-unity-webgl

React Unity WebGL provides a modern solution for embedding Unity WebGL builds in your React Application while providing advanced APIs for two way communication and interaction between Unity and React.

Home Page:https://react-unity-webgl.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Boolean parameters doesnt seem to work

angelhodar opened this issue · comments

commented

Please avoid duplicates

Language and Compiler

Vanilla JavaScript

What environment are you using?

Local Development Server

When does your problem occur?

When the Unity App is running

What does your problem relate to?

The problem seems Unity related

React-Unity-WebGL Version

8.7.4

React Version

17.0.2

Unity Version

2020.3.23f1

What happened?

Hey, congratulations for this amazing library! I have been testing and found that booleans doesnt work as parameter of send (ints and strings work perfectly). The thing is that Unity documentation doesnt seem to support booleans:

SendMessage(objectName, methodName, value);

Where objectName is the name of an object in your scene; methodName is the name of a method in the script, currently attached to that object; value can be a string, a number, or can be empty.

Do you internally cast it to int or something before sending to SendMessage? You say in documentation that booleans can be sent too. I havent seen anything related to this in the issues so it seems strange. Here you have the code in both sides and the exception thrown by Unity:

Uncaught false is does not have a type which is supported by SendMessage.

Below is the code i have used to reproduce the issue, just create a method and pass a boolean

Reproducible test case

React

useEffect(() => {
  const focus = show ? 1 : 0;
  unityContext.send("WebGLEditorManager", "OnEditorChangeFocusInt", focus);
  unityContext.send("WebGLEditorManager", "OnEditorChangeFocusBoolean", show);
}, [show]);

Unity

public void OnEditorChangeFocusBoolean(bool newFocus)
{
    Debug.Log($"Received value {newFocus} on editor change bool");
}

public void OnEditorChangeFocusInt(int newFocus)
{
    Debug.Log($"Received value {newFocus} on editor change int");
}

Would you be interested in contributing a fix?

  • yes, I would like to contribute a fix
commented

Sorry i have found they are not supported in the discussion section! Just make sure you update the docs to fix that!!

Hi. This is actually documented, I hope this helps you. Happy coding.

https://github.com/jeffreylanters/react-unity-webgl#javascript-to-unityscript-types