Repository navigation
Add _onlyIf and _onStart preconditions (#820, #895) - #1261
Merged
Merged
Conversation
- `_onlyIf="<script>"`: if false when the node is IDLE, return SKIPPED (the opposite of `_skipIf`, more readable in most cases). - `_onStart="<script>"`: execute a script right before the first tick() of the node, i.e. only if no other precondition returned a status. Useful to initialize or reset blackboard entries. Both are evaluated only when the node is IDLE/SKIPPED, like `_skipIf`. ONLY_IF and ON_START are appended at the end of PreCond, so the values of the existing ones don't change. Appending ONLY_IF after WHILE_TRUE keeps the semantics: SKIP_IF, WHILE_TRUE and ONLY_IF all return SKIPPED. Behavior change: the attribute names `_onlyIf` and `_onStart` are now reserved. Before, they were stored silently as non-port attributes and did nothing. Supersedes #821 and #932. Co-Authored-By: Darko Lukic <2135826+lukicdarkoo@users.noreply.github.com> Co-Authored-By: Aglargil <34728006+Aglargil@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 25, 2026
Closed
…cument _onStart/_onlyIf caveats Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…activeSequence, WriteTreeToXML) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
facontidavide
added a commit
to vivoeiva/BehaviorTree.CPP
that referenced
this pull request
Nov 8, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ME1hnSFSzibU5phxboGsjk
facontidavide
added a commit
to vivoeiva/BehaviorTree.CPP
that referenced
this pull request
Nov 8, 2026
Master gained the _onlyIf/_onStart preconditions (BehaviorTree#1261) and the BTCPP_version root attribute (BehaviorTree#1264); the checked-in XSD was stale and the new 'generated schemas are up to date' CI step would fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ME1hnSFSzibU5phxboGsjk
facontidavide
added a commit
that referenced
this pull request
Nov 8, 2026
* Add 'generic' parameter to writeTreeXSD() When generic=true, oneNodeGroup uses xs:any processContents="lax" instead of a closed xs:choice, allowing unknown custom node elements to pass validation. Top-level xs:element declarations are also emitted so that lax processing can still resolve and validate the known built-in node types by name. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Add generate_xsd tool Generates the generic XSD schema from the default factory (built-in nodes only) and prints it to stdout, suitable for use as a generic static validator that stays in sync with the built-in node inventory. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix non-deterministic port attribute order in writeTreeXSD() PortsList is an unordered_map so iterating it directly produced XSD attributes in hash-table order, which varies across runs and platforms. Sort ports into a std::map before emitting xs:attribute elements. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Add writeTreeSchematron() for cross-reference validation of BT XML files XSD alone cannot express constraints like "every custom node element used in a BehaviorTree body must have a matching TreeNodesModel entry" Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Add generate_schematron tool Generates an ISO Schematron schema (btcpp4.sch) complementing the generic XSD Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Add generated XSD and Schematron schemas * Add validate_xml.py - XSD and Schematron validation tool Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Only built-ins should go into generic xsd file * Add tests for writeTreeXSD() and writeTreeSchematron() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix implicit conversion * Also handle inout_port in XSD * Fix reconfiguration after editing src/btcpp4_schematron.sch * Fix writeTreeXSD() signature not to break ABI * Change placeholder replacement logic for Schematron * Add more test cases for InsideXmlComment() * Add xsd and schematron checks to CI (intentionally broken) * Fix clang-format issues * Regenerate schemas to pass CI * Add guard for --no-xsd --no-sch together to validate_xml.py * Remove rule checking explicit notation against TreeNodeModel * Regenerate Schematron file * Add Schematron Rule B: explicit-notation node structure constraints Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Regenerate Schematron file * Drop insideXmlComment(): keep the placeholder out of the template comment insideXmlComment() was added to the public xml_parsing.h only so that writeTreeSchematron() could skip the ##BUILTIN_PIPE## placeholder where the template comment mentions it. Rewording the comment so it no longer contains the placeholder makes a plain replace-all enough, removes the helper from the public API, and also fixes the generated bt4.sch, whose comment still described an unexpanded placeholder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Regenerate tools/generated/bt4.xsd for _onlyIf, _onStart, BTCPP_version Master gained the _onlyIf/_onStart preconditions (#1261) and the BTCPP_version root attribute (#1264); the checked-in XSD was stale and the new 'generated schemas are up to date' CI step would fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ME1hnSFSzibU5phxboGsjk * Regenerate bt4.xsd and bt4.sch for the Finally node (#1229) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ME1hnSFSzibU5phxboGsjk --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Davide Faconti <davide.faconti@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Closes #820 and #895. Supersedes #821 (@lukicdarkoo) and #932 (@Aglargil), who are credited as co-authors.
_onlyIf="<script>": if false when the node is IDLE, return SKIPPED (the opposite of_skipIf)._onStart="<script>": run a script right before the firsttick()of the node, only if no other precondition returned a status first.Both are evaluated only when the node is IDLE/SKIPPED, like
_skipIf. Evaluation order:_failureIf,_successIf,_skipIf,_while,_onlyIf,_onStart.Compatibility
ONLY_IFandON_STARTare appended at the end ofPreCond(Add onlyIf precondition #821 insertedONLY_IFin the middle, which changed the existing values).PreCond::COUNT_andTreeNode::PreScriptsget longer, but binaries built against the old headers only read the first four entries, which have not changed.ONLY_IFafterWHILE_TRUEkeeps the semantics:_skipIf,_whileand_onlyIfall return SKIPPED, so their relative order doesn't matter._onlyIfand_onStartare now reserved attribute names. Before, they were stored silently as non-port attributes and did nothing._skipIfstopped working unless_onlyIfwas also present.Also updated
XSD precondition group,
docs/pre_postconditions.md,docs/name_validation_rules.md.Tests
5 new tests in
gtest_preconditions.cpp. They cover the order (_onStartruns after the checks and not when another precondition short-circuits), running once per execution (again after a halt), and_onlyIfvs_skipIfand_while. All 5 fail on master; 600/600 pass with this PR.🤖 Generated with Claude Code