@@ -542,6 +542,20 @@ Tween::Tween(SceneTree *p_parent_tree) {
542542 valid = true ;
543543}
544544
545+ double PropertyTweener::_get_custom_interpolated_value (const Variant &p_value) {
546+ const Variant *argptr = &p_value;
547+
548+ Variant result;
549+ Callable::CallError ce;
550+ custom_method.callp (&argptr, 1 , result, ce);
551+ if (ce.error != Callable::CallError::CALL_OK) {
552+ ERR_FAIL_V_MSG (false , " Error calling custom method from PropertyTweener: " + Variant::get_callable_error_text (custom_method, &argptr, 1 , ce) + " ." );
553+ } else if (result.get_type () != Variant::FLOAT) {
554+ ERR_FAIL_V_MSG (false , vformat (" Wrong return type in PropertyTweener custom method. Expected float, got %s." , Variant::get_type_name (result.get_type ())));
555+ }
556+ return result;
557+ }
558+
545559Ref<PropertyTweener> PropertyTweener::from (const Variant &p_value) {
546560 Ref<Tween> tween = _get_tween ();
547561 ERR_FAIL_COND_V (tween.is_null (), nullptr );
@@ -638,25 +652,20 @@ bool PropertyTweener::step(double &r_delta) {
638652 if (time < duration) {
639653 if (custom_method.is_valid ()) {
640654 const Variant t = tween->interpolate_variant (0.0 , 1.0 , time, duration, trans_type, ease_type);
641- const Variant *argptr = &t;
642-
643- Variant result;
644- Callable::CallError ce;
645- custom_method.callp (&argptr, 1 , result, ce);
646- if (ce.error != Callable::CallError::CALL_OK) {
647- ERR_FAIL_V_MSG (false , " Error calling custom method from PropertyTweener: " + Variant::get_callable_error_text (custom_method, &argptr, 1 , ce) + " ." );
648- } else if (result.get_type () != Variant::FLOAT) {
649- ERR_FAIL_V_MSG (false , vformat (" Wrong return type in PropertyTweener custom method. Expected float, got %s." , Variant::get_type_name (result.get_type ())));
650- }
651-
655+ double result = _get_custom_interpolated_value (t);
652656 target_instance->set_indexed (property, Animation::interpolate_variant (initial_val, final_val, result));
653657 } else {
654658 target_instance->set_indexed (property, tween->interpolate_variant (initial_val, delta_val, time, duration, trans_type, ease_type));
655659 }
656660 r_delta = 0 ;
657661 return true ;
658662 } else {
659- target_instance->set_indexed (property, final_val);
663+ if (custom_method.is_valid ()) {
664+ double final_t = _get_custom_interpolated_value (1.0 );
665+ target_instance->set_indexed (property, Animation::interpolate_variant (initial_val, final_val, final_t ));
666+ } else {
667+ target_instance->set_indexed (property, final_val);
668+ }
660669 r_delta = elapsed_time - delay - duration;
661670 _finish ();
662671 return false ;
0 commit comments