You are here:

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 Unreal Engine to LightAct.

Writing to Shared Memory in Unreal Engine

LightAct Unreal Engine Plugin adds a number of additional nodes that we will be using in this tutorial:

Open shared memory

openSharedMemory

This node is used to create a shared memory handle. It should be called once before all other nodes related to writing to shared memory (such as Write to shared memory and Close shared memory nodes). In most cases, you’ll want to connect it to Event BeginPlay node.

Write to shared memory

writeToSharedMemory

This node is used to write data to shared memory handle. It takes in a Map of Strings to Strings and converts it to JSON before writing it to shared memory.

Close shared memory

closeSharedMemory

This node is for closing shared memory handle. It should be called once before quitting the game. The Handle Name property should be the same as in the Open shared memory node. In most cases, you’ll want to connect it to Event EndPlay node.

Opening and Closing Shared Memory

In Unreal Engine, in either Level Blueprint or a blueprint of one of the actors reproduce the following graph:

opening and closing shared memory

This graph, at Begin Play, creates a shared memory handle with vars2LA Handle Name and 1024 Handle Size. At End Play event, it closes the same shared memory handle. These values should, especially the Handle Name, match what you’ll type in to Write to shared memory node in Unreal and Shared memory reader node in LightAct.

Writing to Shared Memory

For writing to shared memory, insert a Write to shared memory node and connect it to Tick node. You can use it in any actor and it will work as long as the Handle Name property is the same as what you typed in Open shared memory node.

write to shared memory connected

You should note the keys you used in the String Map as you’ll need to type them in LightActas well.

Setting up a JSON Memory Reader in LightAct

The starting point in setting up Shared Memory Reader node is in the Devices window.

addJSONReader

You right-click somewhere in the empty area, hover above JSON sharer and click on Add reader.

shared memory reader

JSON memory reader node has 1 property:

  • Handle name is the identifier which allows the receiving application to know which part of the memory is the starting point. This should match the Handle Name input on the Unreal’s side.

After you’ve entered it, check the Streaming checkbox. You might see a warning saying No shared memory file, which means that there is no shared memory handle with this name. This warning should disappear after you’ve set everything up correctly on Unreal’s side and Unreal is in Play mode (either Play-in-Editor, Standalone or Packaged).

Setup in Layer Layouts

After you’ve set up the JSON memory reader in the Devices window you can proceed to set up a Layer Layout.

shared memory listener

Create a layer and in its Layout, insert a Shared memory listener node.

parent device of shared memory listener

As with most listener nodes you have to select the Parent device. Select the memory reader node you created before. Then, click on Add pair button.

shared memory listener add pair

A Key string input and a Value string output will appear and most likely you’ll see a Key not found error. Once you type in the correct Key (it should match one of the keys used in the String Map on the Unreal’s side) the warning will disappear and the Value output will be the value with the Key in the String Map.shared memory listener connected

Previous Sending Variables from LightAct to Unreal Engine