Skip to content

Commit

Permalink
keep track of last frame error in graph player
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrea-c committed Jan 31, 2024
1 parent 50ad32a commit 2094380
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
44 changes: 31 additions & 13 deletions crates/bevy_animation_graph/src/core/animation_graph_player.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{
animation_graph::{AnimationGraph, InputOverlay, TimeState, TimeUpdate},
context::DeferredGizmos,
errors::GraphError,
parameters::ParamValue,
pose::{BoneId, Pose},
};
Expand All @@ -19,6 +20,9 @@ pub struct AnimationGraphPlayer {
pub(crate) deferred_gizmos: DeferredGizmos,

input_overlay: InputOverlay,
/// Error that ocurred during graph evaluation in the last frame
#[reflect(ignore)]
error: Option<GraphError>,
}

impl AnimationGraphPlayer {
Expand All @@ -33,6 +37,7 @@ impl AnimationGraphPlayer {
deferred_gizmos: DeferredGizmos::default(),

input_overlay: InputOverlay::default(),
error: None,
}
}

Expand Down Expand Up @@ -83,19 +88,26 @@ impl AnimationGraphPlayer {
return None;
};

Some(
graph
.query_with_overlay(
self.elapsed.update,
&mut self.context,
system_resources,
&self.input_overlay,
root_entity,
entity_map,
&mut self.deferred_gizmos,
)
.unwrap_or(Pose::default()),
)
let pose = match graph.query_with_overlay(
self.elapsed.update,
&mut self.context,
system_resources,
&self.input_overlay,
root_entity,
entity_map,
&mut self.deferred_gizmos,
) {
Ok(pose) => {
self.error = None;
pose
}
Err(error) => {
self.error = Some(error);
Pose::default()
}
};

Some(pose)
}

pub fn pause(&mut self) -> &mut Self {
Expand All @@ -120,4 +132,10 @@ impl AnimationGraphPlayer {
pub fn get_animation_graph(&self) -> Option<Handle<AnimationGraph>> {
self.animation.clone()
}

/// If graph evaluation produced an error in the last frame return the error, otherwise return
/// `None`.
pub fn get_error(&self) -> Option<GraphError> {
self.error.clone()
}
}
2 changes: 1 addition & 1 deletion crates/bevy_animation_graph/src/core/errors/graph_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use thiserror::Error;

/// Possible errors that can be produced by graph evaluation
#[non_exhaustive]
#[derive(Debug, Error)]
#[derive(Debug, Error, Reflect, Clone)]
pub enum GraphError {
#[error("Expected an edge connected to {0:?}")]
MissingInputEdge(TargetPin),
Expand Down

0 comments on commit 2094380

Please sign in to comment.