@adamdbrw Hi Adam, Not to be too politically incorrect, but the included examples are simply rubbish. It’s in no way cool to be subscribing to events on Unity’s main loop!!
I would like to help with two things:
- Figure out how to subscribe to and handle the ROS2 message topics in a more Unity-friendly way, AND,
- Update the included examples based on the outcome of #1
In summary, I’d describe the existing ROS2 for Unity examples as an anti-pattern for how to make asynch data (that is, data created on a different thread and with unrelated timing) available in Unity’s main loop. Let’s find a better way!! I’m happy to point out an example if it will help!
@cloudconstable-mike the best place for such a post would be in the Issues of ros2-for-unity GitHub project. Otherwise, in short, it is not about being politically correct, but simply just correct.
I am assuming that you mean ROS2ListenerExample and if you postulate that callbacks are handled in the main thread, this is incorrect.
While examples are there to show the simplest case, if you would look into the code of a primary component, you would see that there is a dedicated thread which handles spinning (and calls all the callbacks). Under the hood, in the spinning there is a loop that goes over subscriptions and calls their Actions.
If this does not answer your concerns, please post an issue on the project GitHub and describe what and why of the anti-pattern.