Skip to content

Communication between Unity and React

Gökhan Kurt edited this page Apr 5, 2020 · 3 revisions

Although there are different ways to do this for advanced use cases, the easiest way to do it is by using NamedAssets. NamedAssets is a dictionary of assets you can send over to the React side from the Unity side.

You can set NamedAssets in the inspector:

inspector

After assigning, you can access your object in React side via the NamedAssets global variable. Here is an example script using NamedAssets. You can download the (full sample project)[https://github.com/KurtGokhan/react-unity-full-sample] and go to "Interop" scene to see this in action.

example

Note: You can set/get an object's public properties and call its public methods from React side. However, if you try to set/get a non-existing or non-public property/method, you will get an error.