You are here:
  • Home
  • Unity
  • Data Sharing in LightAct for Unity

Setting up data sharing starts in the Devices window, so let’s open the window by pressing F7 or by going to Window and then pressing Devices. Good!

First, we’ll set up receiving data from Unity in LightAct.

Receiving Data from Unity in LightAct

The node in the Devices window we will explore now, is called JSON memory reader 1. If you select it, you will see Handle name says vars2LA.  In the Data section you can also see some data in JSON format. We can’t explain the whole JSON format here, but please do notice that there are 2 pieces of data in our incoming JSON:

  • sphereHeight is a number going up and down and
  • sphereText is a text saying: “Hello from that blue sphere in Unity”

All you need to know at this point is that sphereHeight and sphereText are JSON Keys and the number and the text are JSON Values.

We’ll need to write the keys into a node later on, but before we do that, let’s finish explaining JSON memory reader node.

I’m sure you noticed the Handle name property is not editable. If you want to make it editable, you have to uncheck Listening checkbox. 

Similarly to Spout name, if you change Handle name property of JSON memory reader node, make sure you change the Handle name in the shared memory writer application. In our case, that is Unity, of course.

Let’s leave Handle name as it is (vars2LA) and check the Listening checkbox again.

We’ve done everything we had to in the Devices window, so its time to close it and open Unity2LA layer.

Setting up Shared Memory Listener node in Layer Layouts

Once Unity2LA layer opens, the node we will start with, is called Shared Memory Listener. Please notice that we typed in the JSON keys (sphereHeight and sphereText) we talked about before.

If you select the node, you will see that we selected our JSON memory reader 1 node as the parent. 

Now, to explain briefly what is happening in the rest of the node chain connected to the Shared Memory Listener node:

  • the Value of sphereHeight key goes to String to Float node, which converts it into float format. Then we multiply the value by 10 and use it as the y value of our blue sphere in the Visualizer.
  • the Value of sphereText key goes to String to Texture node, which transforms the text into a texture and then we bring the resulting texture into a Render to Canvas node, which renders it on top of the incoming Spout texture.

Sending data from LightAct to Unity

To explain how to send data from LightAct to Unity let’s go back to the Devices window.

This time, let’s select JSON memory writer node. If you uncheck the Streaming checkbox you should see something similar to above.

Let’s go through the properties very quickly:

  • Handle name is the name of the shared memory handle. You can type in whatever you want (almost) as long as you use the exact same Handle name on Unity side.
  • Reserved bytes is the amount of memory that should be reserved for this package of data. 1024 should much more than enough.
  • In the Data section you can see whatever LightAct is currently writing to shared memory.

Before we close the Devices window, just make sure you check Streaming checkbox back again. Once you’ve done that, close Devices window and open LA2Unity layer.

The node that we will focus on is Shared Memory Sender. As you can see it has 4 inputs:

  • Float is a float value we are sending
  • FName is the JSON key under which we are sending the preceding float value
  • String is a string value we are sending
  • SName is the JSON key under which we are sending preceding string value.

As you can see, every value of whatever type we are sending, has to be followed by a key under which we are sending it.

That’s how we will be able to know under which key we should look under for a particular value on Unity side.

The only thing that we still need to explain is Shared Memory Sender‘s properties. If you select it you will see that as the Parent device, we’ve selected our JSON Memory Writer node in the Devices window.