docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    ROS Endpoint Connector reference

    Look up RosEndpointConnector inspector properties, wire encoding details, and API for use outside a MonoBehaviour.

    Inspector properties

    The following properties appear on the RosEndpointConnectorComponent in the Inspector when you add it to a GameObject.

    Property Default Description
    EndpointIPAddress 127.0.0.1 IP address or hostname of the ROS TCP Endpoint server.
    EndpointPort 10000 TCP port of the ROS TCP Endpoint server.
    IsRos2 true (ROS 2 define) / false Whether to use ROS 2 CDR wire encoding. Must match the server.
    KeepaliveTime 1 s Idle seconds before a keepalive packet is sent to detect connection loss.
    NetworkTimeoutSeconds 2 s Read timeout on the TCP socket.
    SleepTimeSeconds 0.01 s Duration the send thread sleeps between outgoing message attempts.
    ConnectOnStart true Whether to call Connect() automatically in Start.
    ShowInHud true Whether to register this connector's header with the ConnectorHud.

    Use RosEndpointConnector directly

    For non-MonoBehaviour contexts, construct RosEndpointConnector directly and call Connect():

    using Unity.SimulationPro.RosIntegrations;
    using Unity.SimulationPro.Foundation;
    
    var connector = new RosEndpointConnector(
        isRos2: true,
        ipAddress: "192.168.1.100",
        port: 10000);
    
    connector.Connect();
    
    // Register a publisher
    IPublisher pub = connector.RegisterPublisher<PoseMsg>("/robot/pose");
    pub.Publish(new PoseMsg(...));
    
    // Subscribe
    connector.Subscribe<TwistMsg>("/cmd_vel", msg =>
    {
        Debug.Log($"Linear X: {msg.linear.x}");
    });
    
    // Disconnect when done
    connector.Disconnect();
    

    Topic introspection

    RosEndpointConnector tracks the set of topics it has seen advertised by the endpoint, so you can inspect or react to them without subscribing:

    // Trigger a refresh of the known topic list (rate-limited to once per 5 s):
    connector.RequestTopicListRefresh();
    
    // Enumerate all known topics:
    foreach (ITopicInfo topic in connector.GetAllTopics())
        Debug.Log($"{topic.Topic} ({topic.MessageTypeId})");
    
    // Get notified when new topics appear:
    connector.AddNewTopicsListener(
        info => Debug.Log($"New topic: {info.Topic}"),
        notifyAllExistingTopics: true);
    

    Wire encoding

    RosEndpointConnector picks a serialization format based on IsRos2:

    • ROS 1 mode (IsRos2 = false): messages are serialized as bare little-endian binary with a 4-byte length prefix.
    • ROS 2 mode (IsRos2 = true): messages are serialized with a 4-byte CDR header followed by eProsima Fast-CDR aligned binary data.

    The RosBinarySerializer and RosBinaryDeserializer classes handle encoding transparently. You do not need to interact with them directly.

    Services

    RosEndpointConnector supports ROS-style request/response calls in both directions.

    Implement a Unity-hosted service (called by ROS):

    connector.ImplementService<SetBoolRequest, SetBoolResponse>(
        "/enable_motor",
        req => new SetBoolResponse { success = req.data });
    

    Call a ROS-hosted service from Unity:

    IServiceClient client = connector.RegisterServiceClient<SetBoolRequest, SetBoolResponse>("/enable_motor");
    

    Additional resources

    • Connect to a live ROS environment
    • Troubleshooting the ROS Endpoint Connector
    • Introduction to messaging
    • Set up publishers and subscribers workflow
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)