@@ -600,6 +600,22 @@ void AnimationMixer::_init_root_motion_cache() {
600
600
root_motion_scale_accumulator = Vector3 (1 , 1 , 1 );
601
601
}
602
602
603
+ void AnimationMixer::_create_track_num_to_track_cashe_for_animation (Ref<Animation> &p_animation) {
604
+ ERR_FAIL_COND (animation_track_num_to_track_cashe.has (p_animation));
605
+ LocalVector<TrackCache *> &track_num_to_track_cashe = animation_track_num_to_track_cashe.insert_new (p_animation, LocalVector<TrackCache *>())->value ;
606
+ const Vector<Animation::Track *> &tracks = p_animation->get_tracks ();
607
+
608
+ track_num_to_track_cashe.resize (tracks.size ());
609
+ for (int i = 0 ; i < tracks.size (); i++) {
610
+ TrackCache **track_ptr = track_cache.getptr (tracks[i]->thash );
611
+ if (track_ptr == nullptr ) {
612
+ track_num_to_track_cashe[i] = nullptr ;
613
+ } else {
614
+ track_num_to_track_cashe[i] = *track_ptr;
615
+ }
616
+ }
617
+ }
618
+
603
619
bool AnimationMixer::_update_caches () {
604
620
setup_pass++;
605
621
@@ -928,20 +944,9 @@ bool AnimationMixer::_update_caches() {
928
944
}
929
945
930
946
animation_track_num_to_track_cashe.clear ();
931
- LocalVector<TrackCache *> track_num_to_track_cashe;
932
947
for (const StringName &E : sname_list) {
933
948
Ref<Animation> anim = get_animation (E);
934
- const Vector<Animation::Track *> tracks = anim->get_tracks ();
935
- track_num_to_track_cashe.resize (tracks.size ());
936
- for (int i = 0 ; i < tracks.size (); i++) {
937
- TrackCache **track_ptr = track_cache.getptr (tracks[i]->thash );
938
- if (track_ptr == nullptr ) {
939
- track_num_to_track_cashe[i] = nullptr ;
940
- } else {
941
- track_num_to_track_cashe[i] = *track_ptr;
942
- }
943
- }
944
- animation_track_num_to_track_cashe.insert (anim, track_num_to_track_cashe);
949
+ _create_track_num_to_track_cashe_for_animation (anim);
945
950
}
946
951
947
952
track_count = idx;
@@ -1074,6 +1079,9 @@ void AnimationMixer::blend_capture(double p_delta) {
1074
1079
1075
1080
capture_cache.remain -= p_delta * capture_cache.step ;
1076
1081
if (Animation::is_less_or_equal_approx (capture_cache.remain , 0 )) {
1082
+ if (capture_cache.animation .is_valid ()) {
1083
+ animation_track_num_to_track_cashe.erase (capture_cache.animation );
1084
+ }
1077
1085
capture_cache.clear ();
1078
1086
return ;
1079
1087
}
@@ -2205,6 +2213,9 @@ void AnimationMixer::capture(const StringName &p_name, double p_duration, Tween:
2205
2213
capture_cache.step = 1.0 / p_duration;
2206
2214
capture_cache.trans_type = p_trans_type;
2207
2215
capture_cache.ease_type = p_ease_type;
2216
+ if (capture_cache.animation .is_valid ()) {
2217
+ animation_track_num_to_track_cashe.erase (capture_cache.animation );
2218
+ }
2208
2219
capture_cache.animation .instantiate ();
2209
2220
2210
2221
bool is_valid = false ;
@@ -2228,6 +2239,8 @@ void AnimationMixer::capture(const StringName &p_name, double p_duration, Tween:
2228
2239
}
2229
2240
if (!is_valid) {
2230
2241
capture_cache.clear ();
2242
+ } else {
2243
+ _create_track_num_to_track_cashe_for_animation (capture_cache.animation );
2231
2244
}
2232
2245
}
2233
2246
0 commit comments