Lightact can send to and receive variables from Unreal Engine 4 via shared memory. It does that using LightAct Unreal Engine Plugin (if you haven’t downloaded it yet, you can do so here).
In this document, we’ll explain how to send variables from LightAct to Unreal Engine.
Setting up a JSON Memory Writer in LightAct
The starting point in setting up shared memory writer is in the Devices window.
You right-click somewhere in the empty area, hover above JSON sharer and click on Add writer.
JSON memory writer node has 2 properties:
- Handle name is the identifier which allows the receiving application to know which part of the memory is the starting point.
- Reserved bytes tells the receiving application how many bytes of the memory it should read starting from the Handle name position. The default value is 1024, which should be enough for most cases.
Make note of these 2 entries as you will have to type them in on the UE4 side. After you’ve entered them, check the Streaming checkbox.
Setup in Layer Layouts
After you’ve set up the JSON memory sharer in the Devices window you can proceed to set up the Layer Layout.
Create a layer and in its Layout, insert a Shared memory sender node.
As with most sender nodes you have to select the Parent device and, of course, connect it to a live Lifeline connection. In the image above I’ve connected it directly to the Run node.
The last thing you need to do is to decide what kind of variables you want to send over to UE4. There are various options: floats, integers, strings and so on. Use whichever you want or as many as you want.
The only important thing to remember is that each Name has to be unique because this is what you’ll use on the UE4 to find the value of the variable in the JSON package.
Setting up a shared memory receiver in Unreal Engine
LightAct Unreal Engine plugin that you installed in the previous chapter adds a few nodes to UE4’s Blueprints. The most important node one is Shared Memory to JSON String Map node.
It reads from the shared memory and outputs the JSON package as a Map of String to Strings. From there you can find the value of any individual variable using Find node. It uses Handle name and Handle size properties that have to match what you typed in the JSON sharer node in LightAct.
The Key input of the Find node has to match the Name of the variable you typed in the Shared memory sender node in LightAct.