You can set up communication with Unreal Engine® by using the Simulation 3D Message Get and Simulation 3D Message Set blocks:
Simulation 3D Message Get receives data from the Unreal Engine environment.
Simulation 3D Message Set sends data to the Unreal Engine environment.
To use the blocks and communicate with Unreal Engine, make sure you install the Vehicle Dynamics Blockset™ Interface for Unreal Engine 4 Projects support package. For more information, see Install Support Package and Configure Environment.
Next, follow these workflow steps to set up the Simulink® model and the Unreal Engine environment and run a simulation.
| Workflow | Description | |
|---|---|---|
| Set Up Simulink Model to Send and Receive Data | Configure the Simulation 3D Message Get and Simulation 3D Message Set blocks in Simulink to send and receive the cone location from Unreal® Editor. The steps provides the general workflow for communicating with the editor. The Simulation 3D
Message Get and Simulation 3D Message Set
blocks can send and receive these data types:
| |
Set Up Unreal Engine to Send and Receive Data | C++ Workflow: Set Up Unreal Engine to Send and Receive Data | Specific Unreal C++ workflow to send and receive Simulink cone location data.
To follow this workflow, you should be comfortable coding with C++ in Unreal Engine 4.23. Make sure that you have Visual Studio® 2019 installed on your computer. |
| Blueprint Workflow: Set Up Unreal Engine to Send and Receive Data | Generalized Unreal Editor blueprint workflow to send and receive Simulink data. | |
| Run Simulation | After you set up the Simulink model and Unreal Editor environment, run a simulation. | |
If you have already downloaded and installed Unreal Engine Version 4.23 and the Vehicle Dynamics Blockset Interface for Unreal Engine 4 Projects support package, go to the next step.
To install and configure the support package, see Install Support Package and Configure Environment.
Open a new Simulink model. Connect the blocks as shown.

Use these block settings to configure blocks to send and receive cone data from the Unreal Editor.
| Block | Parameter Settings |
|---|---|
Constant |
|
Data Type Conversion |
|
Simulation 3D Scene Configuration |
|
Simulation 3D Message Get |
|
| Simulation 3D Message Set |
|
In the Unreal Editor, on the Edit tab, select
Plugins. Make sure that the
MathWorks Interface plugin is enabled. If
prompted, restart the Unreal Editor.
Create an Unreal Engine C++ project. Name it TestSim3dGetSet.
For steps on how to create C++ project, see the Unreal Engine 4
Documentation.
In the Unreal Editor, click the Edit tab in the top
left corner. Select Plugins and make sure that the
MathWorks Interface plugin is enabled. If
the MathWorks Interface plugin is disabled,
enable it and restart Unreal Editor, if prompted.
Close the Unreal.
If Visual Studio is not open, open it.
Add the MathWorksSimulation dependency to the
TestSim3dGetSet project build file.
The project build file,
TestSim3dGetSet.Build.cs, is located
in this folder:
...\TestSim3dGetSet\Source\TestSim3dGetSet.
In the build file,
TestSim3dGetSet.Build.cs, edit the
line 11 to add the “MathWorksSimulation”
dependency:
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject",
"Engine", "InputCore", "MathWorksSimulation"});
Save the change. In Visual Studio, rebuild the TestSim3dGetSet project.
Close Visual Studio.
Tip
Before rebuilding the project in Visual Studio, make sure that Unreal is not open.
Start MATLAB®. Change the current folder to the location of the
Unreal Engine
TestSim3dGetSet project.
In MATLAB, open the project:
editor = sim3d.Editor('TestSim3dGetSet.uproject');
editor.open();
In the Unreal Editor, from the MathWorksSimulation C++ classes directory, select Sim3dActor.

Right-click and select Create C++ class derived from Sim3dActor.

Name the new Sim3dActor SetGetActorLocation. Select
Public. Click Create
Class.
Close the Unreal Editor.
SetGetActorLocation.hVisual Studio opens with new C++ files in the project folder:
SetGetActorLocation.h
SetGetActorLocation.cpp
Make sure you close the Unreal Editor.
In Visual Studio, build the solution TestSim3dGetSet:
In the Solution Explorer, right-click Solution 'TestSim3dGetSet' (2 projects).
Select Build Solution.
After the solution builds, open
SetGetActorLocation.h. Edit the file as
shown.
SetGetActorLocation.cppOpen SetGetActorLocation.cpp and replace the block of
code.
Replacement Code: Set Pointer to Parameter
Replacement Code: Access Actor Tag Name
Additional Code: Read and Write Data During Run Time
Press F5 on the keyboard to run the Visual Studio solution TestSim3dGetSet. The Unreal Editor opens.
Note
In the Unreal Editor, save the current level by clicking Save
Current (located in the top left) and name it
TestMap. Add this level as default to Project Settings by
clicking on Edit > Project Settings > Maps&Modes. Then select TestMap as the default value for
the Editor Startup Map and Game Default Map. Close Project Settings to save the
default values.


On the World Outliner tab, check that the new instantiated
actor, SetGetActorLocation1, is listed.

Click on the actor that you created in Step 9: Check Actor.
In the Details panel, click on Add Component to
add a mesh to the actor SetConeLocation1. Choose
Cone as the default mesh.
Find the property tags for actor SetConeLocation1.
Add a tag by clicking on the plus sign next to 0 Array elements. Name it
ConeLoc.

On the Details tab, click Cone. Set the
cone to X = 0.0, Y = 0.0, and Z =
0.0. Also set the actor Mobility
property to Movable.

Set the parent class.
Under Blueprints, click Open Level Blueprint, and select Class Settings.

In the Class Options, set Parent Class to
Sim3dLevelScriptActor.

Save the Unreal Editor scene.
Run the simulation. Go to Run Simulation.
Call these C++ functions from Sim3dSetup, Sim3dStep, and Sim3dRelease to send and receive Simulink data.
To use the Simulation 3D Message Set block, you must configure scenes in the Unreal Engine environment to receive data from the Simulink model:
In the Unreal Editor, instantiate the Sim3DGet actor
that corresponds to the data type you want to receive from the
Simulink model. This example shows the Unreal Editor Sim3DGet data types.

Specify an actor tag name that matches the Simulation 3D Message Set block Signal name parameter.
Navigate to the Level Blueprint.
Find the blueprint method for the Sim3DGet actor
class based on the data type and size that you want to receive from the
Simulink model.
For example, in Unreal Editor, this diagram shows that Read Scalar
Integer is the method for
Sim3DGetInteger actor class to receive
int32 data type of size scalar.

Compile and save the scene.
To configure scenes in the Unreal Engine environment to send data to the Simulink model:
In the Unreal Editor, instantiate the Sim3DSet actor
that corresponds to the data type you want to send to the Simulink model. This example shows the Unreal Editor Sim3DSet data types.

Specify an actor tag name that matches the Simulation 3D Message Get block Signal name parameter.
Navigate to the Level Blueprint.
Find the blueprint method for the Sim3DSet actor
class based on the data type and size specified by the Simulation
3D Message Get block Data type and
Message size parameters.
For this example, the array size is 3. The Unreal Editor diagram shows that Write Array
Float is the method for the
Sim3DSetFloat3 actor class that sends float data
type of array size 3.

Compile and save the scene.
Note
Optionally, for better performance, set Read Array Float Max Num
Elements to Num El in the Actor Blueprint.

In the Unreal Editor, create a level blueprint connecting the Get and Set actors.
Set the actor tag values.
Sim3dGetFloat1 — Simulation 3D
Message Set block Signal name,
SigName parameter value, for example
ConeLocSet
Sim3dSetFloat1 — Simulation 3D
Message Get block Signal name,
SigName parameter value, for example
ConeLocGet
Set the parent class.
Under Blueprints, click Open Level Blueprint, and select Class Settings.

In the Class Options, set Parent Class to
Sim3dLevelScriptActor.

In the level blueprint, make the connections, for example:

Run the simulation. Go to Run Simulation.
After you configure the Simulink model and Unreal Editor environment, you can run the simulation.
Note
At the BeginPlay event, Simulink does not receive data from the Unreal Editor. Simulink receives data at Tick events.
Run the simulation.
In the Simulink model, click Run.
Because the source of the scenes is the project opened in the Unreal Editor, the simulation does not start.
Verify that the Diagnostic Viewer window in Simulink displays this message:
In the Simulation 3D Scene Configuration block, you set the scene source to 'Unreal Editor'. In Unreal Editor, select 'Play' to view the scene.
This message confirms that Simulink has instantiated the vehicles and other assets in the Unreal Engine 3D environment.
In the Unreal Editor, click Play. The simulation runs in the scene currently open in the Unreal Editor.
You can send and receive these data types: double,
single, int8, uint8,
int16, uint16, int32,
uint32, boolean. The code in Step 7: Open SetGetActorLocation.cpp reads single data
type values (or float values) from Simulink.
ASim3dActor | Sim3dRelease | Sim3dSetup | Sim3dStep | Simulation 3D
Message Get | Simulation 3D
Message Set | Simulation 3D
Scene Configuration