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 Vehicle Dynamics Blockset Interface for Unreal Engine 4 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® 2019 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 identifier1

    • Vehicle nameScene Origin

    • Vehicle mounting locationOrigin

    • Specify offseton

    • Relative translation [X, Y, Z][-5, 0, 1]

      This offsets the camera location from the cone mounting location, 5 m behind, and 1 m up.

  2. In the Unreal Editor, 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 World 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, under Actor, tag the Sim3DSceneCap with the name Camera1.

    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 Vehicle Dynamics Blockset Interface for Unreal Engine 4 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 Vehicle Advanced template from the Epic Games Launcher by Epic Games®.

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

      Epic games launcher

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

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

      Unreal engine games projects

    3. In Select Template, select the Vehicle Advanced template and Next.

      Select template

    4. In Project Settings, create a Blueprint or C++ project, and select a project name and location. Click Create Project.

      Project settings

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

    5. Enable the MathWorks Interface plugin.

      1. Select Edit > Plugins.

      2. On the Plugins tab, navigate to MathWorks Interface. Select Enabled.

        Project settings

    6. Save the project. Close the Unreal Editor.

  3. Open the Simulink model that you saved in step 1. 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 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 sceneMainCamera1

    ActTranslation

    • Constant value[-11310.0 - 300 8140.0 100]/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, from the Place Actors tab, add a Sim 3d Scene Cap to the world, scene, or map.

    Unreal editor modes tab with image of camera

    Unreal editor modes tab with image of camera

  6. On the vehicle VehicleBlueprint, drag and drop a camera. Choose a vehicle socket or bone to attach the camera to.

    Sockets and bones available in Unreal Editor

  7. On the Details tab, tag the Sim3dSceneCap1 with the name Camera1.

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

      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.

    Observe the results in the To Video Display window.

    View of vehicle in roadway

See Also

|

Related Topics

External Websites