Skip to content

Commit

Permalink
Make AnimationTree reference AnimationPlayer instead of AnimationMixer
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyqiu committed Dec 15, 2023
1 parent f8a2a91 commit 7946e84
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions scene/animation/animation_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include "animation_blend_tree.h"
#include "core/config/engine.h"
#include "scene/animation/animation_player.h"
#include "scene/scene_string_names.h"

void AnimationNode::get_parameter_list(List<PropertyInfo> *r_list) const {
Expand Down Expand Up @@ -764,25 +765,26 @@ void AnimationTree::_setup_animation_player() {
return;
}

AnimationMixer *mixer = Object::cast_to<AnimationMixer>(get_node_or_null(animation_player));
if (mixer) {
if (!mixer->is_connected(SNAME("caches_cleared"), callable_mp(this, &AnimationTree::_setup_animation_player))) {
mixer->connect(SNAME("caches_cleared"), callable_mp(this, &AnimationTree::_setup_animation_player), CONNECT_DEFERRED);
// Using AnimationPlayer here is for compatibility. Changing to AnimationMixer needs extra work like error handling.
AnimationPlayer *player = Object::cast_to<AnimationPlayer>(get_node_or_null(animation_player));
if (player) {
if (!player->is_connected(SNAME("caches_cleared"), callable_mp(this, &AnimationTree::_setup_animation_player))) {
player->connect(SNAME("caches_cleared"), callable_mp(this, &AnimationTree::_setup_animation_player), CONNECT_DEFERRED);
}
if (!mixer->is_connected(SNAME("animation_list_changed"), callable_mp(this, &AnimationTree::_setup_animation_player))) {
mixer->connect(SNAME("animation_list_changed"), callable_mp(this, &AnimationTree::_setup_animation_player), CONNECT_DEFERRED);
if (!player->is_connected(SNAME("animation_list_changed"), callable_mp(this, &AnimationTree::_setup_animation_player))) {
player->connect(SNAME("animation_list_changed"), callable_mp(this, &AnimationTree::_setup_animation_player), CONNECT_DEFERRED);
}
Node *root = mixer->get_node_or_null(mixer->get_root_node());
Node *root = player->get_node_or_null(player->get_root_node());
if (root) {
set_root_node(get_path_to(root, true));
}
while (animation_libraries.size()) {
remove_animation_library(animation_libraries[0].name);
}
List<StringName> list;
mixer->get_animation_library_list(&list);
player->get_animation_library_list(&list);
for (int i = 0; i < list.size(); i++) {
Ref<AnimationLibrary> lib = mixer->get_animation_library(list[i]);
Ref<AnimationLibrary> lib = player->get_animation_library(list[i]);
if (lib.is_valid()) {
add_animation_library(list[i], lib);
}
Expand Down

0 comments on commit 7946e84

Please sign in to comment.