Property clear caches in animationtree if animatioplayer is modified. Fixes #19876

This commit is contained in:
Juan Linietsky 2018-08-24 11:41:04 -03:00
parent d72a281468
commit f6c0a3fce9
2 changed files with 36 additions and 0 deletions

View file

@ -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() {

View file

@ -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;