pub struct Fallbacks { /* private fields */ }Expand description
The Fallback behavior is used to try different strategies until one succeeds.
It implements 3 modes, which differ in how they handle a childs return value:
- The synchronous mode will try to succeed within one tick from its parent.
If any child returns
BehaviorState::Running, previous children will NOT be ticked again.- If a child returns
BehaviorState::Failure, continue to the next sibling. If all the children fail, than this node returnsBehaviorState::Failure. - If a child returns
BehaviorState::Running, this node returnsBehaviorState::Runningand continues with the same child at the next tick from parent. - If a child returns
BehaviorState::Successthis behavior returnsBehaviorState::Success.
- If a child returns
- The asynchronous mode will return the flow contol after a childs failure to its parent.
If any child returns
BehaviorState::Running, previous children will NOT be ticked again.- If a the children returns
BehaviorState::Failure, this node returnsBehaviorState::Running. and continues with the next child at the next tick from parent. If all the children fail, than this node returnsBehaviorState::Failure. - If a child returns
BehaviorState::Running, this node returnsBehaviorState::Runningand continues with the same child at the next tick from parent. - If a child returns
BehaviorState::Successthis behavior returnsBehaviorState::Success.
- If a the children returns
- The reactive mode always ticks all children from first to last:
If any child returns
BehaviorState::Running, previous children will be ticked again. IMPORTANT: Having asynchronous children (aka children that returnBehaviorState::Running) makes this behavior difficult to predict. Avoid having more than one asynchronous children!- If a child returns
BehaviorState::Running, continue to the next sibling. - If a child returns
BehaviorState::Failure, continue to the next sibling. If all the children fail, than this node returnsBehaviorState::Failure. - If a child returns
BehaviorState::Success, stop running child and returnBehaviorState::Success.
- If a child returns
The variants are gated behind features fallback,async_fallback and reactive_fallback respectively.
Examples:
The synchronous variant is gated behind feature fallback.
<Fallback>
<Behavior1/>
<Behavior2/>
<Behavior3/>
</Fallback>The asynchronous variant is gated behind feature async_fallback.
<AsyncFallback>
<Behavior1/>
<Behavior2/>
<Behavior3/>
</AsyncFallback>Implementations§
Source§impl Fallbacks
impl Fallbacks
Sourcepub const fn new(kind: FallbackKind) -> Self
pub const fn new(kind: FallbackKind) -> Self
Returns a Fallback behavior with the given kind.
Sourcepub fn create_fn(kind: FallbackKind) -> Box<BehaviorCreationFn>
pub fn create_fn(kind: FallbackKind) -> Box<BehaviorCreationFn>
Creates a creation_fn() for Fallback with the given kind.
Sourcepub fn register_with(
registry: &mut impl BehaviorRegistry,
name: &str,
kind: FallbackKind,
) -> Result<(), Error>
pub fn register_with( registry: &mut impl BehaviorRegistry, name: &str, kind: FallbackKind, ) -> Result<(), Error>
Trait Implementations§
Source§impl Behavior for Fallbacks
impl Behavior for Fallbacks
Source§fn on_start(
&mut self,
behavior: &mut BehaviorData,
_children: &mut BehaviorTreeElementList,
_runtime: &SharedRuntime,
) -> Result<(), Error>
fn on_start( &mut self, behavior: &mut BehaviorData, _children: &mut BehaviorTreeElementList, _runtime: &SharedRuntime, ) -> Result<(), Error>
Method is called before starting to tick a behavior,
intended to do preliminary stuff for your behavior. Read more
Source§fn tick<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 mut self,
_behavior: &'life1 mut BehaviorData,
children: &'life2 mut BehaviorTreeElementList,
runtime: &'life3 SharedRuntime,
) -> Pin<Box<dyn Future<Output = BehaviorResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn tick<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 mut self,
_behavior: &'life1 mut BehaviorData,
children: &'life2 mut BehaviorTreeElementList,
runtime: &'life3 SharedRuntime,
) -> Pin<Box<dyn Future<Output = BehaviorResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Method to tick a behavior. Read more
Source§fn on_halt(&mut self) -> Result<(), Error>
fn on_halt(&mut self) -> Result<(), Error>
Method called during stop/cancel/halt of a behavior,
intended to reset the internal fields of your behavior. Read more
Source§fn start<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 mut self,
behavior: &'life1 mut BehaviorData,
children: &'life2 mut BehaviorTreeElementList,
runtime: &'life3 SharedRuntime,
) -> Pin<Box<dyn Future<Output = BehaviorResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn start<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 mut self,
behavior: &'life1 mut BehaviorData,
children: &'life2 mut BehaviorTreeElementList,
runtime: &'life3 SharedRuntime,
) -> Pin<Box<dyn Future<Output = BehaviorResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Method is called on first tick of a behavior instead of
tick().
If this method returns BehaviorState::Running, the
behavior becomes asynchronous. Read moreSource§fn halt(
&mut self,
_behavior: &mut BehaviorData,
children: &mut BehaviorTreeElementList,
runtime: &SharedRuntime,
) -> BehaviorResult
fn halt( &mut self, _behavior: &mut BehaviorData, children: &mut BehaviorTreeElementList, runtime: &SharedRuntime, ) -> BehaviorResult
Method to halt a behavior. Read more
Source§impl BehaviorExecution for Fallbacks
impl BehaviorExecution for Fallbacks
Source§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Mutable dynamic downcasting.
Source§fn kind(&self) -> BehaviorKind
fn kind(&self) -> BehaviorKind
Get the
BehaviorKind of the behavior.Source§fn portlist_mut(&mut self) -> &mut dyn PortList
fn portlist_mut(&mut self) -> &mut dyn PortList
Access the
PortListSource§impl PortCollectionProvider for Fallbacks
impl PortCollectionProvider for Fallbacks
Source§fn provided_ports(&self) -> &impl PortCollectionAccessors
fn provided_ports(&self) -> &impl PortCollectionAccessors
Returns immutable access to the collections entries.
Source§fn provided_ports_mut(&mut self) -> &mut impl PortCollectionAccessors
fn provided_ports_mut(&mut self) -> &mut impl PortCollectionAccessors
Returns mutable access to the collections entries.
Source§fn port_collection(&self) -> &impl PortCollection
fn port_collection(&self) -> &impl PortCollection
Returns an immutable
PortCollection.Auto Trait Implementations§
impl Freeze for Fallbacks
impl RefUnwindSafe for Fallbacks
impl Send for Fallbacks
impl Sync for Fallbacks
impl Unpin for Fallbacks
impl UnsafeUnpin for Fallbacks
impl UnwindSafe for Fallbacks
Blanket Implementations§
Source§impl<T> AnyPortValue for T
impl<T> AnyPortValue for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more