| 441 | } |
| 442 | |
| 443 | Tree BehaviorTreeFactory::createTreeFromFile(const std::filesystem::path& file_path, |
| 444 | Blackboard::Ptr blackboard) |
| 445 | { |
| 446 | // Determine the main tree from the XML before loading into the shared parser. |
| 447 | tinyxml2::XMLDocument doc; |
| 448 | doc.LoadFile(file_path.string().c_str()); |
| 449 | std::string main_tree_ID; |
| 450 | if(const auto* root = doc.RootElement()) |
| 451 | { |
| 452 | main_tree_ID = detectMainTreeId(root); |
| 453 | } |
| 454 | |
| 455 | const std::string resolved_ID = loadXmlAndResolveTreeId( |
| 456 | _p->parser.get(), main_tree_ID, [&] { _p->parser->loadFromFile(file_path); }); |
| 457 | |
| 458 | // Set the polymorphic cast registry on the blackboard (Issue #943) |
| 459 | blackboard->setPolymorphicCastRegistry(_p->polymorphic_registry); |
| 460 | |
| 461 | Tree tree = resolved_ID.empty() ? _p->parser->instantiateTree(blackboard) : |
| 462 | _p->parser->instantiateTree(blackboard, resolved_ID); |
| 463 | tree.manifests = this->manifests(); |
| 464 | tree.remapManifestPointers(); |
| 465 | return tree; |
| 466 | } |
| 467 | |
| 468 | Tree BehaviorTreeFactory::createTree(const std::string& tree_name, |
| 469 | Blackboard::Ptr blackboard) |