Transform broadcasting example
Review an example of publishing a transform hierarchy and subscribing to it on the /tf topic.
Publish a transform hierarchy
Attaching TfBroadcasterComponent to your robot's root GameObject in the scene is the only step required. The component publishes on /tf automatically, so no additional code is necessary. Refer to Publish your scene's transform hierarchy.
Subscribe to a transform hierarchy
To subscribe to /tf from another component, create a SubscriberBehaviour<TFMessageMsg>:
using Unity.Simulation.Foundation;
using Unity.Simulation.Foundation.Tf2Messages;
using System;
using UnityEngine;
public class TfListener : SubscriberBehaviour<TFMessageMsg>
{
public override string DefaultTopic => "/tf";
protected override Action<TFMessageMsg> Callback => msg =>
{
foreach (var transform in msg.transforms)
{
Debug.Log($"{transform.header.frame_id} -> {transform.child_frame_id}");
}
};
}