Scene setup workflow
Learn how to set up your scene for Simulation Pro.
To set up your scene for Simulation Pro, follow these steps:
- Add a connector
- Add a sensor
- Publish a message
- Subscribe to a message
- Configure the transform broadcast hierarchy
- Configure compass direction
Add a connector
A connector is the bridge between your Unity scene and an external messaging back end. Two options are available:
Dummy connection component
The Dummy Connection Component works without any back end. This component is useful for development and testing.
- Create an empty GameObject (for example
ROS Connection). - Add Dummy Connection Component to it.
ROS endpoint connector component
The Robot Operating System (ROS) Endpoint Connector Component connects to a live ROS environment via the ROS TCP Endpoint bridge.
- Create an empty GameObject (for example
ROS Connection). - Add Ros Endpoint Connector Component to it.
- Set Endpoint IP Address and Endpoint Port to match your ROS TCP Endpoint server.
- Set Is Ros 2 to match your ROS version.
ConnectorInjector discovers the active BaseConnectionComponent automatically. If multiple connectors exist in the scene, the one closest to the scene root takes priority.
Add a sensor
To add a sensor to your scene:
- Select a GameObject in your scene. For the IMU sensor, the GameObject must already have an ArticulationBody component; other sensors add their own required components automatically.
- Add a sensor component, for example Camera Sensor.
- Configure the topic names and parameters in the Inspector.
- Press Play. The sensor starts publishing immediately once the connector is active.
For a full list of available sensors and their configuration options, refer to Sensor types reference.
Publish a message
To publish a message, add the following code to any GameObject in your scene:
using Unity.SimulationPro.Foundation;
using Unity.SimulationPro.Foundation.StdMessages;
using UnityEngine;
public class HelloPublisher : PublisherBehaviour<StringMsg>
{
public override string DefaultTopic => "/hello";
void Update()
{
if (CanPublish)
Publish(new StringMsg("Hello from Unity!"));
}
}
PublisherBehaviour<T> resolves the connector automatically in Start().
Subscribe to a message
Use the following code to subscribe to a message:
using System;
using Unity.SimulationPro.Foundation;
using Unity.SimulationPro.Foundation.StdMessages;
using UnityEngine;
public class HelloSubscriber : SubscriberBehaviour<StringMsg>
{
public override string DefaultTopic => "/hello";
protected override Action<StringMsg> Callback =>
msg => Debug.Log($"Received: {msg.data}");
}
Configure the transform broadcast hierarchy
Add TfBroadcasterComponent to the root GameObject of your robot. You don't need to add any additional code. The component publishes the full transform tree to /tf on every FixedUpdate.
Configure compass direction
NED and ENU coordinate spaces require knowing which cardinal direction Unity's z-axis represents. Configure this once per project before you perform any coordinate conversion:
// Set once, e.g. in a scene initializer
CompassDirection.UnityZAxisDirection = CardinalDirection.North;
In the Unity Editor, configure this via the Simulation > Simulation Settings menu.