Skip to content

Commit ae880fe

Browse files
committed
fix: child graph contexts now use the correct graph reference
1 parent c8288bd commit ae880fe

3 files changed

Lines changed: 36 additions & 10 deletions

File tree

crates/bevy_animation_graph_builtin_nodes/src/graph_node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl NodeLike for GraphNode {
4141
};
4242

4343
let sub_ctx = ctx
44-
.create_child_context(self.graph.id(), None)
44+
.create_child_context(self.graph.id(), graph, None)
4545
.with_io(&sub_ctx_io);
4646

4747
if graph.io_spec.has_output_time() {
@@ -70,7 +70,7 @@ impl NodeLike for GraphNode {
7070
};
7171

7272
let mut sub_ctx = ctx
73-
.create_child_context(self.graph.id(), None)
73+
.create_child_context(self.graph.id(), graph, None)
7474
.with_io(&sub_ctx_io);
7575

7676
if graph.io_spec.has_output_time() {

crates/bevy_animation_graph_core/src/context/new_context.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ impl<'a> NodeContext<'a> {
292292
pub fn create_child_context(
293293
&self,
294294
subgraph_id: AssetId<AnimationGraph>,
295+
// We pass the subgraph to avoid a wasted asset lookup in the hot path
296+
subgraph: &'a AnimationGraph,
295297
fsm_state: Option<LowLevelStateId>,
296298
) -> GraphContext<'a> {
297299
let subctx_id = SubContextId {
@@ -306,7 +308,25 @@ impl<'a> NodeContext<'a> {
306308
.context_arena
307309
.get_mut()
308310
.get_sub_context_or_insert_default(subctx_id, subgraph_id),
311+
graph: subgraph,
309312
..self.graph_context.clone()
310313
}
311314
}
315+
316+
pub fn create_child_context_id(
317+
&self,
318+
subgraph_id: AssetId<AnimationGraph>,
319+
fsm_state: Option<LowLevelStateId>,
320+
) -> GraphContextId {
321+
let subctx_id = SubContextId {
322+
ctx_id: self.graph_context.context_id,
323+
node_id: self.node_id.to_owned(),
324+
state_id: fsm_state,
325+
};
326+
327+
self.graph_context
328+
.context_arena
329+
.get_mut()
330+
.get_sub_context_or_insert_default(subctx_id, subgraph_id)
331+
}
312332
}

crates/bevy_animation_graph_core/src/state_machine/low_level/mod.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,15 @@ impl LowLevelStateMachine {
264264
}
265265

266266
if let Some((graph, state)) = should_clear {
267-
ctx.create_child_context(graph, Some(state))
268-
.node_states_mut()
269-
.clear();
267+
let subctx_id = ctx.create_child_context_id(graph, Some(state));
268+
if let Some(graph_state) = ctx
269+
.graph_context
270+
.context_arena
271+
.get_mut()
272+
.get_context_mut(subctx_id)
273+
{
274+
graph_state.node_states.clear();
275+
}
270276
}
271277

272278
Ok(())
@@ -351,7 +357,7 @@ impl LowLevelStateMachine {
351357
);
352358

353359
let sub_ctx = ctx
354-
.create_child_context(state.graph.id(), Some(state.id.clone()))
360+
.create_child_context(state.graph.id(), graph, Some(state.id.clone()))
355361
.with_io(&sub_io_env);
356362

357363
for (id, _) in graph.io_spec.iter_output_data() {
@@ -424,7 +430,7 @@ impl LowLevelStateMachine {
424430
);
425431

426432
let sub_ctx = ctx
427-
.create_child_context(state.graph.id(), Some(state.id.clone()))
433+
.create_child_context(state.graph.id(), graph, Some(state.id.clone()))
428434
.with_io(&sub_io_env);
429435

430436
let source_pin = SourcePin::InputTime(GraphInputPin::Passthrough(pin));
@@ -510,7 +516,7 @@ impl<'a> FsmIoEnv<'a> {
510516

511517
let sub_ctx = self
512518
.node_context
513-
.create_child_context(graph_handle.id(), Some(next_state))
519+
.create_child_context(graph_handle.id(), graph, Some(next_state))
514520
.with_state_key(ctx.state_key)
515521
.with_io(&sub_graph_io);
516522

@@ -562,7 +568,7 @@ impl<'a> FsmIoEnv<'a> {
562568

563569
let sub_ctx = self
564570
.node_context
565-
.create_child_context(graph_handle.id(), Some(state))
571+
.create_child_context(graph_handle.id(), graph, Some(state))
566572
.with_state_key(ctx.state_key)
567573
.with_io(&sub_graph_io);
568574

@@ -604,7 +610,7 @@ impl<'a> FsmIoEnv<'a> {
604610

605611
let sub_ctx = self
606612
.node_context
607-
.create_child_context(graph_handle.id(), Some(next_state))
613+
.create_child_context(graph_handle.id(), graph, Some(next_state))
608614
.with_state_key(ctx.state_key)
609615
.with_io(&sub_graph_io);
610616

0 commit comments

Comments
 (0)