Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tween with float property will be forced to interpolate as int type when passing int to Tween's argument #87326

Closed
saierXP opened this issue Jan 18, 2024 · 5 comments · Fixed by #87459

Comments

@saierXP
Copy link

saierXP commented Jan 18, 2024

Tested versions

4.2.1

System information

windows10

Issue description

tween-int-float

extends Node2D

func _ready() -> void:
	var t := create_tween()
	t.set_parallel()
	t.tween_property($Icon1,'rotation', PI, 1).from(0) # row1 left
	t.tween_property($Icon2,'rotation', PI, 1).from(0.0) # row1 right
	t.tween_property($Icon3,'rotation', PI, 1).as_relative().from(0) # row2 left
	t.tween_property($Icon4,'rotation', PI, 1).as_relative().from(0.0) # row2 right

tween interpolates by the type of the from argument, not the float type of the property.
Does not work if as_relative is used.

Steps to reproduce

Run the MRP project attached below.

Minimal reproduction project (MRP)

tween-int.zip

@jsjtxietian
Copy link
Contributor

jsjtxietian commented Jan 18, 2024

Related to #73178 and #74112

Reading the code, it seems godot does use the from value to determine final value.
But the final value is validated by the property value type in tween_property already, IMHO it should validate the from value by the final value instead of doing the opposite.

cc @KoBeWi

@KoBeWi
Copy link
Member

KoBeWi commented Jan 20, 2024

I'm getting a different result in 4.3 dev2:

xXrqr0kLWU.mp4

Seems like this was fixed by some of the animation changes.

Can you confirm the issue is fixed for you in the newest version?

@saierXP
Copy link
Author

saierXP commented Jan 20, 2024

Can you confirm the issue is fixed for you in the newest version?

The as_relative().from(0) one was fixed, but from(0) wasn't.

@TokageItLab
Copy link
Member

TokageItLab commented Jan 20, 2024

Fixed by #86046

but from(0) wasn't.

Not sure what you are referring to, but if you mix Int and float, the float will take precedence to make subsequent transitions consistent. This is an intended behavior.

If you have any other problems, please check the latest master or 4.3.dev2 or later versions and report them if you still have problems.

@TokageItLab TokageItLab added this to the 4.3 milestone Jan 20, 2024
@kleonc
Copy link
Member

kleonc commented Jan 21, 2024

but from(0) wasn't.

Not sure what you are referring to, but if you mix Int and float, the float will take precedence to make subsequent transitions consistent. This is an intended behavior.

If you have any other problems, please check the latest master or 4.3.dev2 or later versions and report them if you still have problems.

See how the t.tween_property($Icon1,'rotation', PI, 1).from(0) # row1 left behaves (top-left in the examples above).

Calling .from(0) makes the tweener tween with integers even though both the property and the final value passed are floats. So it's not true that float always take precendence in case of mixing float/int.

To me it seems like unintended behavior / bug.


Specifically when calling from(an_int) both initial_val and final_val end up being ints:

Ref<PropertyTweener> PropertyTweener::from(const Variant &p_value) {
ERR_FAIL_COND_V(tween.is_null(), nullptr);
if (!tween->_validate_type_match(p_value, final_val)) {
return nullptr;
}
initial_val = p_value;

} else if (p_from.get_type() == Variant::INT && r_to.get_type() == Variant::FLOAT) {
r_to = int(r_to);

Hence delta_val etc. is int:

delta_val = Animation::subtract_variant(final_val, initial_val);

@TokageItLab TokageItLab changed the title [Type mismatch] Tween interpolates by the int type of the from argument, not the float type of the property. Tween with float property will be forced to interpolate as int type when passing int as an argument Jan 21, 2024
@TokageItLab TokageItLab reopened this Jan 21, 2024
@TokageItLab TokageItLab changed the title Tween with float property will be forced to interpolate as int type when passing int as an argument Tween with float property will be forced to interpolate as int type when passing int as an argument of Tween Jan 21, 2024
@TokageItLab TokageItLab changed the title Tween with float property will be forced to interpolate as int type when passing int as an argument of Tween Tween with float property will be forced to interpolate as int type when passing int to Tween's argument Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants