Main Content

Place Cameras on Actors in the Unreal Editor

To visualize objects in an Unreal® Editor scene, you can place cameras on static or custom actors in the scene. To start, you need the Aerospace Blockset Interface for Unreal Engine projects support package. See Install Support Package and Configure Environment.

To follow this workflow, you should be comfortable using Unreal Engine®. Make sure that you have Visual Studio® 2022 installed on your computer.

Place Camera on Static Actor

Follow these steps to place a Simulation 3D Camera Get block that is offset from a cone in the Unreal Editor. Although this example uses the To Video Display block from Computer Vision Toolbox™, you can use a different visualization block to display the image.

  1. In a Simulink® model, add the Simulation 3D Scene Configuration, Simulation 3D Camera Get, and To Video Display blocks.

    Simulink model with blocks

    Set these block parameters. In the Simulation 3D Scene Configuration block, select Open Unreal Editor.

    BlockParameter Settings

    Simulation 3D Scene Configuration

    • Scene SourceUnreal Editor

    • Project — Specify the path and name of the support package project file. For example, C:\Local\AutoVrtlEnv\AutoVrtlEnv.uproject

    Simulation 3D Camera Get

    • Sensor identification1

    • Vehicle nameScene Origin

    • Vehicle mounting locationOrigin

    • Specify offseton

    • Relative translation [X, Y, Z][-6, 0, 2]

      This offsets the camera location from the cone mounting location, 6 m behind, and 2 m up.

    • Relative rotation [Roll, Pitch, Yaw][0, 15, 0]

  2. In the Unreal Editor, from the File > Open Level, select HwStraight. From the Place Actors tab, add a Sim 3d Scene Cap to the world, scene, or map.

    Unreal Editor Place Actors tab

  3. In the Unreal Editor, from the Place Actors tab, add a Cone to the world, scene, or map.

    Unreal Editor Place Actors tab

  4. On the Outliner tab, right-click the Sim3DSceneCap and attach it to the Cone.

    Unreal Editor World Outliner tab

  5. On the Details tab, under Transform, add a location offset of -500,0,100 in the X, Y, and Z world coordinate system, respectively. This attaches the camera 500 cm behind the cone and 100 cm above it. The values match the Simulation 3D Camera Get block parameter Relative translation [X, Y, Z] value.

    Unreal Editor set transformation values

  6. On the Details tab, tag the Sim3DSceneCap with the name IdealCamera1.

    Unreal Editor set name values

  7. Run the simulation.

    1. 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.

    2. 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.

    3. In the Unreal Editor, click Play. The simulation runs in the scene currently open in the Unreal Editor.

    Observe the results in the To Video display window. The window displays the image from the camera.

    Cone on road

Place Camera on Vehicle in Custom Project

Follow these steps to create a custom Unreal Engine project and place a camera on a vehicle in the project. Although the example uses the To Video Display block from Computer Vision Toolbox, you can use a different visualization block to display the image.

To start, you need the Aerospace Blockset™ Interface for Unreal Engine Projects support package. See Install Support Package and Configure Environment.

  1. In a Simulink model, add the Simulation 3D Scene Configuration, Simulation 3D Camera Get, To Video Display, Simulation 3D Actor Transform Set, and three Constant blocks.

    Simulink model with blocks

    Save the model.

  2. Create a new project using the Flying template from the Epic Games Launcher by Epic Games®.

    1. In the Epic Games Launcher, launch Unreal Engine 5.3.

      Epic games launcher

      For more information about the Epic Games Launcher, see Unreal Engine.

    2. In the Unreal Project Browser, select Games and VehicleFlying.

      Select template

    3. In the browser, create a Blueprint or C++ project. Provide a project name and location. Click Create.

      Project settings

      The Epic Games Launcher creates a new project and opens the Unreal Editor.

    4. Enable the MathWorks® plugins.

      1. Select Edit > Plugins.

      2. On the Plugins tab, navigate to MathWorks. Select Enabled for the content you want to enable, including MathWorks Interface.

        Mathworks Plugins in Unreal Editor

    5. Save the project. Close the Unreal Editor.

  3. Open the Simulink model that you saved in step 1. Set these block parameters.

    BlockParameter Settings

    Simulation 3D Scene Configuration

    • Scene SourceUnreal Editor

    • Project — Specify the path an project that you saved in step 2. For example, myProjectPath\myProject.uproject

    Simulation 3D Camera Get

    • Sensor identifier1

    • Vehicle nameScene Origin

    • Vehicle mounting locationOrigin

    Simulation 3D Actor Transform Set

    • Tag for actor in 3D sceneCamera1

    ActTranslation

    • Constant value[-400, -50, 50]/100

    • Interpret vector parameters as 1-Doff

    ActRotation

    • Constant value[0 0 0]

    • Interpret vector parameters as 1-Doff

    ActScale

    • Constant value[1 1 1]

    • Interpret vector parameters as 1-Doff

  4. In the Simulation 3D Scene Configuration block, select Open Unreal Editor.

  5. In the Unreal Editor, in the Content Browser navigate to Sim3DCamera under the MathWorksSimulation C++ folder. Add it to the map by dragging it into the viewport.Unreal Editor modes tab with image of camera

  6. In World Outliner, drag and drop the camera onto the FlyingPawn blueprint.

  7. On the Details tab, tag the Sim3dSceneCap with the name IdealCamera1.

    Unreal Editor details tab with tag name

  8. Set the parent class.

    1. Under Blueprints, click Open Level Blueprint, and select Class Settings.

      Unreal Editor Work Outliner tab

    2. In the Class Options, set Parent Class to Sim 3d Level Script Actor.

      Unreal Editor class settings

  9. Save the project.

  10. Run the simulation.

    1. 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.

    2. 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.

    3. In the Unreal Editor, click Play. The simulation runs in the scene currently open in the Unreal Editor.

See Also

|

Related Topics

External Websites