summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scene/animation/animation_tree.cpp34
-rw-r--r--scene/animation/animation_tree.h2
2 files changed, 36 insertions, 0 deletions
diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp
index 76f0ee9359..d084369a0e 100644
--- a/scene/animation/animation_tree.cpp
+++ b/scene/animation/animation_tree.cpp
@@ -674,6 +674,7 @@ void AnimationTree::_clear_caches() {
cache_valid = false;
}
+
void AnimationTree::_process_graph(float p_delta) {
_update_properties(); //if properties need updating, update them
@@ -698,6 +699,29 @@ void AnimationTree::_process_graph(float p_delta) {
AnimationPlayer *player = Object::cast_to<AnimationPlayer>(get_node(animation_player));
+ ObjectID current_animation_player =0;
+
+ if (player) {
+ current_animation_player=player->get_instance_id();
+ }
+
+ if (last_animation_player != current_animation_player) {
+
+ if (last_animation_player) {
+ Object *old_player = ObjectDB::get_instance(last_animation_player);
+ if (old_player) {
+ old_player->disconnect("caches_cleared",this,"_clear_caches");
+ }
+ }
+
+ if (player) {
+ player->connect("caches_cleared",this,"_clear_caches");
+ }
+
+ last_animation_player = current_animation_player;
+
+ }
+
if (!player) {
ERR_PRINT("AnimationTree: path points to a node not an AnimationPlayer, disabling playback");
set_active(false);
@@ -1197,6 +1221,14 @@ void AnimationTree::_notification(int p_what) {
if (p_what == NOTIFICATION_EXIT_TREE) {
_clear_caches();
+ if (last_animation_player) {
+
+ Object *old_player = ObjectDB::get_instance(last_animation_player);
+ if (old_player) {
+ old_player->disconnect("caches_cleared",this,"_clear_caches");
+ }
+ }
+
}
}
@@ -1447,6 +1479,7 @@ void AnimationTree::_bind_methods() {
ClassDB::bind_method(D_METHOD("advance", "delta"), &AnimationTree::advance);
ClassDB::bind_method(D_METHOD("_node_removed"), &AnimationTree::_node_removed);
+ ClassDB::bind_method(D_METHOD("_clear_caches"), &AnimationTree::_clear_caches);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "tree_root", PROPERTY_HINT_RESOURCE_TYPE, "AnimationRootNode"), "set_tree_root", "get_tree_root");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "anim_player", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "AnimationPlayer"), "set_animation_player", "get_animation_player");
@@ -1468,6 +1501,7 @@ AnimationTree::AnimationTree() {
setup_pass = 1;
started = true;
properties_dirty = true;
+ last_animation_player =0;
}
AnimationTree::~AnimationTree() {
diff --git a/scene/animation/animation_tree.h b/scene/animation/animation_tree.h
index 70f3932f21..6cb363d50a 100644
--- a/scene/animation/animation_tree.h
+++ b/scene/animation/animation_tree.h
@@ -266,6 +266,8 @@ private:
void _update_properties_for_node(const String &p_base_path, Ref<AnimationNode> node);
+ ObjectID last_animation_player;
+
protected:
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;