pub trait InputContextAppExt {
// Required method
fn add_input_context_to<S: ScheduleLabel + Default, C: Component>(
&mut self,
) -> &mut Self;
// Provided method
fn add_input_context<C: Component>(&mut self) -> &mut Self { ... }
}Expand description
An extension trait for App to assign input to components.
Required Methods§
Sourcefn add_input_context_to<S: ScheduleLabel + Default, C: Component>(
&mut self,
) -> &mut Self
fn add_input_context_to<S: ScheduleLabel + Default, C: Component>( &mut self, ) -> &mut Self
Like Self::add_input_context, but allows specifying the schedule
in which the context’s actions will be evaluated.
For example, if your game logic runs inside FixedMain, you can set the schedule
to FixedPreUpdate. This way, if the schedule runs multiple times per frame, events like Start or
Complete will be triggered only once per schedule run.
Provided Methods§
Sourcefn add_input_context<C: Component>(&mut self) -> &mut Self
fn add_input_context<C: Component>(&mut self) -> &mut Self
Registers type C as an input context, whose actions will be evaluated during PreUpdate.
Action evaluation follows these steps:
- If the action has an
ActionMockcomponent, use the mockedActionValueandActionStatedirectly. - Otherwise, evaluate the action from its bindings:
- Iterate over each binding from the
Bindingscomponent.- Read the binding input as an
ActionValue, orActionValue::zeroif the input was already consumed by another action. The enum variant depends on the input source. - Apply all binding-level
InputModifiers. - Evaluate all input-level
InputConditions, combining their results based on theirInputCondition::kind.
- Read the binding input as an
- Select all
ActionValues with the most significantActionStateand combine them using theActionSettings::accumulationstrategy. - Convert the combined value to
ActionOutput::DIMusingActionValue::convert. - Apply all action-level
InputModifiers. - Evaluate all action-level
InputConditions, combining their results based on theirInputCondition::kind. - Convert the final value to
ActionOutput::DIMagain usingActionValue::convert. - Apply the resulting
ActionStateandActionValueto the action entity. - If the final state is not
ActionState::None, consume the binding input value.
- Iterate over each binding from the
This logic may look complicated, but you don’t have to memorize it. It behaves surprisingly intuitively.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.