From 14329e606ecf35fd66c537024fbd79caf91c3ade Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Mon, 2 Feb 2026 20:38:55 +0100 Subject: [PATCH] Properly initialize animation player when loading a scene. --- blendalot_animation_graph.cpp | 33 +++++++++++++++------------------ blendalot_animation_graph.h | 1 + demo/main.tscn | 1 + 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/blendalot_animation_graph.cpp b/blendalot_animation_graph.cpp index 38d07aa..56d6109 100644 --- a/blendalot_animation_graph.cpp +++ b/blendalot_animation_graph.cpp @@ -149,7 +149,7 @@ void BLTAnimationGraph::_notification(int p_what) { GodotProfileZone("SyncedAnimationGraph::_notification"); switch (p_what) { - case Node::NOTIFICATION_READY: { + case NOTIFICATION_ENTER_TREE: { _setup_evaluation_context(); _setup_graph(); @@ -234,16 +234,9 @@ AnimationMixer::AnimationCallbackModeDiscrete BLTAnimationGraph::get_callback_mo } void BLTAnimationGraph::set_animation_player(const NodePath &p_path) { - animation_player_path = p_path; - if (p_path.is_empty()) { - // set_root_node(SceneStringName(path_pp)); - // while (animation_libraries.size()) { - // remove_animation_library(animation_libraries[0].name); - // } - } - graph_context.animation_player = Object::cast_to(get_node_or_null(animation_player_path)); + print_line(vformat("set_animation_player(%s) ", p_path)); - print_line(vformat("Setting animation player of graph %x to %x", (uintptr_t)(this), (uintptr_t)graph_context.animation_player)); + animation_player_path = p_path; _setup_evaluation_context(); _setup_graph(); @@ -279,14 +272,9 @@ Ref BLTAnimationGraph::get_root_animation_node() const { } void BLTAnimationGraph::set_skeleton(const NodePath &p_path) { + print_line(vformat("set_skeleton(%s) ", p_path)); + skeleton_path = p_path; - if (p_path.is_empty()) { - // set_root_node(SceneStringName(path_pp)); - // while (animation_libraries.size()) { - // remove_animation_library(animation_libraries[0].name); - // } - } - graph_context.skeleton_3d = Object::cast_to(get_node_or_null(skeleton_path)); _setup_evaluation_context(); _setup_graph(); @@ -365,11 +353,20 @@ void BLTAnimationGraph::_set_process(bool p_process, bool p_force) { processing = p_process; } +void BLTAnimationGraph::_setup_animation_player() { + if (!is_inside_tree()) { + return; + } + + graph_context.animation_player = Object::cast_to(get_node_or_null(animation_player_path)); + print_line(vformat("AnimationPlayer of graph %x is now %x", (uintptr_t)(this), (uintptr_t)graph_context.animation_player)); +} + void BLTAnimationGraph::_setup_evaluation_context() { print_line("_setup_evaluation_context()"); _cleanup_evaluation_context(); - graph_context.animation_player = Object::cast_to(get_node_or_null(animation_player_path)); + _setup_animation_player(); graph_context.skeleton_3d = Object::cast_to(get_node_or_null(skeleton_path)); } diff --git a/blendalot_animation_graph.h b/blendalot_animation_graph.h index 807d2c0..3298979 100644 --- a/blendalot_animation_graph.h +++ b/blendalot_animation_graph.h @@ -76,6 +76,7 @@ public: private: void _set_process(bool p_process, bool p_force = false); + void _setup_animation_player(); void _setup_evaluation_context(); void _cleanup_evaluation_context(); diff --git a/demo/main.tscn b/demo/main.tscn index 22da37c..3385af8 100644 --- a/demo/main.tscn +++ b/demo/main.tscn @@ -279,6 +279,7 @@ bones/66/position = Vector3(-0.014239848, 6.412128, 0.0079107955) active = false [node name="AnimationPlayer2" type="AnimationPlayer" parent="Characters/MixamoAmyWalkRunSynced" unique_id=1255239074] +active = false libraries/animation_library = ExtResource("3_1bvp3") [node name="SyncedAnimationGraph" type="BLTAnimationGraph" parent="Characters/MixamoAmyWalkRunSynced" unique_id=1602406394]