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 Automated Driving Toolbox Interface for Unreal Engine Projects support package. See Install Support Package for Customizing Scenes.

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 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, 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

    • Sensor identification1

    • Parent nameScene Origin

    • Mounting locationOrigin

    • Specify offseton

    • Relative translation [X, Y, Z] (m)[-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 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 Sim3DSceneCap1 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 block parameter Relative translation [X, Y, Z] (m) value.

    Unreal Editor set transformation values

  6. On the Details tab, under Actor, tag the Sim3DSceneCap1 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 Automated Driving Toolbox Interface for Unreal Engine Projects support package. See Install Support Package for Customizing Scenes.

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

    Simulink model with blocks

    Save the model.

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

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

      Epic games launcher

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

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

      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

    • Sensor identifier1

    • Parent nameScene Origin

    • Mounting locationOrigin

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

  5. In the Unreal Editor, in the Content Browser navigate to Sim3DCamera. Add it to the world, scene, or map.

    Unreal editor modes tab with image of camera

  6. On the vehicle VehicleBlueprint, drag and drop the 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 Sim3dCamera1 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 Sim 3d Level Script Actor.

      Unreal Editor class settings

  9. Optionally, use a level blueprint to set up a camera view that overrides the default view in the Unreal Editor. For information about creating level blueprints, see Set up Camera View (Optional) (Vehicle Dynamics Blockset).

  10. Save the project.

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

|

External Websites