Reusing same instance of node across tree
Closed this issue · 1 comments
Is there a way to reuse the same instance of a behavior in multiple places of the tree?
I have a behavior that contains a service server and I want to re-use this exact behavior including the same instance of a ROS2 service server and callbacks in multiple places.
Basically telling the tree instead of creating another copy of a behavior, that it should use a reference to another (previously instantiated) behavior that it should tick?
Kind of like creating a portal for teleporting behaviors between different locations of the tree.
no. Each instance is unique, because it is stateful. Shared instances is a feature that will NEVER be implemented.
I understand that this may seem like a limitation (and it is).
The best solution to your problem is to pass the service as a shared_ptr as an argument of the Node.
https://github.com/BehaviorTree/BehaviorTree.CPP/blob/master/examples/t08_additional_node_args.cpp