Hello,
I publish and subscribe to a ROS topic in Unity with my own msg and srv. I followed this tutorial: Unity-Robotics-Hub/tutorials/ros_unity_integration at main · Unity-Technologies/Unity-Robotics-Hub · GitHub
Publishing works without issues but the subscriber gets this error: I still receive the message and can print it.
InvalidCastException: Specified cast is not valid.
(wrapper castclass) System.Object.__castclass_with_cache(object,intptr,intptr)
Unity.Robotics.ROSTCPConnector.ROSConnection+<>c__DisplayClass78_01[T].<Subscribe>b__0 (Unity.Robotics.ROSTCPConnector.MessageGeneration.Message msg) (at Library/PackageCache/com.unity.robotics.ros-tcp-connector@c27f00c6cf/Runtime/TcpConnector/ROSConnection.cs:194) Unity.Robotics.ROSTCPConnector.RosTopicState+<>c__DisplayClass56_0.<OnMessageReceived>b__0 (System.Action
1[T] item) (at Library/PackageCache/com.unity.robotics.ros-tcp-connector@c27f00c6cf/Runtime/TcpConnector/RosTopicState.cs:94)
System.Collections.Generic.List1[T].ForEach (System.Action
1[T] action) (at :0)
Unity.Robotics.ROSTCPConnector.RosTopicState.OnMessageReceived (System.Byte[ ] data) (at Library/PackageCache/com.unity.robotics.ros-tcp-connector@c27f00c6cf/Runtime/TcpConnector/RosTopicState.cs:94)
Unity.Robotics.ROSTCPConnector.ROSConnection.Update () (at Library/PackageCache/com.unity.robotics.ros-tcp-connector@c27f00c6cf/Runtime/TcpConnector/ROSConnection.cs:600)
UnityEngine.Debug:LogException(Exception)
Unity.Robotics.ROSTCPConnector.ROSConnection:Update() (at Library/PackageCache/com.unity.robotics.ros-tcp-connector@c27f00c6cf/Runtime/TcpConnector/ROSConnection.cs:605)
My subscriber:
void Start()
{
//subscribe to topic name and call funtion Print
ROSConnection.GetOrCreateInstance().Subscribe(topicName, Print);
}
//msg is the data from the publisher
void Print(DigitalTwinMsg msg)
{
Debug.Log(msg);
}