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

Animation::blend_variant() can't handle Array type #73342

Closed
Tracked by #83401
RaSeHo opened this issue Feb 15, 2023 · 16 comments · Fixed by #84815
Closed
Tracked by #83401

Animation::blend_variant() can't handle Array type #73342

RaSeHo opened this issue Feb 15, 2023 · 16 comments · Fixed by #84815

Comments

@RaSeHo
Copy link

RaSeHo commented Feb 15, 2023

Godot version

4rc2

System information

Windows 10, Vulcan, Intel HD graphics 620

Issue description

In Godot 3.5 AnimationTree works fine with animated polygons with Continuous update mode. But in 4.0 branch it works only with Discrete update type.

Steps to reproduce

Add Polygon2D.
Add AnimationPlayer
Animate polygon property of Polygon2D. Set Continuous update type.
Trigger that animation with AnimationTree.
And poly will disappear.

Minimal reproduction project

Scene

[gd_scene load_steps=5 format=3 uid="uid://b6crv38nygato"]

[sub_resource type="Animation" id="Animation_5ir0w"]
resource_name = "new_animation"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Polygon2D:polygon")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 1),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [PackedVector2Array(-89, -164, 282, -91, 246, 16, -263, 20), PackedVector2Array(298, -267, 282, -91, 246, 16, -263, 20)]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_2re6j"]
_data = {
"new_animation": SubResource("Animation_5ir0w")
}

[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_knmkm"]
animation = &"new_animation"

[sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_fiaw4"]
graph_offset = Vector2(-467.78, 0)
nodes/Animation/node = SubResource("AnimationNodeAnimation_knmkm")
nodes/Animation/position = Vector2(-120, 120)
node_connections = [&"output", 0, &"Animation"]

[node name="Node2D" type="Node2D"]

[node name="Polygon2D" type="Polygon2D" parent="."]

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_2re6j")
}

[node name="AnimationTree" type="AnimationTree" parent="."]
tree_root = SubResource("AnimationNodeBlendTree_fiaw4")
anim_player = NodePath("../AnimationPlayer")
active = true
@akien-mga
Copy link
Member

Could you provide a minimal reproduction project? This makes debugging and fixing issues much easier.

@TokageItLab
Copy link
Member

TokageItLab commented Feb 15, 2023

I assume this is due to the RESET animation not being set correctly. See https://docs.godotengine.org/en/latest/tutorials/animation/animation_tree.html#for-better-blending.

@RaSeHo
Copy link
Author

RaSeHo commented Feb 15, 2023

With RESET it appear, thanks, but it not animating poly.

[gd_scene load_steps=6 format=3 uid="uid://b6crv38nygato"]

[sub_resource type="Animation" id="Animation_5ir0w"]
resource_name = "new_animation"
loop_mode = 2
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Polygon2D:polygon")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 1),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [PackedVector2Array(-89, -164, 282, -91, 246, 16, -263, 20), PackedVector2Array(298, -267, 282, -91, 246, 16, -263, 20)]
}

[sub_resource type="Animation" id="Animation_re46f"]
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Polygon2D:polygon")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [PackedVector2Array(-89, -164, 282, -91, 246, 16, -263, 20)]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_2re6j"]
_data = {
"RESET": SubResource("Animation_re46f"),
"new_animation": SubResource("Animation_5ir0w")
}

[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_knmkm"]
animation = &"new_animation"

[sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_fiaw4"]
graph_offset = Vector2(-467.78, 0)
nodes/Animation/node = SubResource("AnimationNodeAnimation_knmkm")
nodes/Animation/position = Vector2(-200, 140)
node_connections = [&"output", 0, &"Animation"]

[node name="Node2D" type="Node2D"]

[node name="Polygon2D" type="Polygon2D" parent="."]
polygon = PackedVector2Array(-89, -164, 282, -91, 246, 16, -263, 20)

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_2re6j")
}

[node name="AnimationTree" type="AnimationTree" parent="."]
tree_root = SubResource("AnimationNodeBlendTree_fiaw4")
anim_player = NodePath("../AnimationPlayer")
active = true

Sorry about use "issues" as qa.

@TokageItLab
Copy link
Member

Please send a Minimal reproduction project as zip.

@TokageItLab
Copy link
Member

TokageItLab commented Feb 15, 2023

Also, Continuous and Discrete cannot be blended. This should display as a warning/error. If you want to blend them, set Discrete to Continuous+Nearest.

@RaSeHo
Copy link
Author

RaSeHo commented Feb 15, 2023

Zero warnings or errors. And that's why I thought about it as about an issue.
BTW
Continuous+Nearest - no result.
Baked and Discrete+any update mode - ugly, but playable by AnimationTree.

@TokageItLab
Copy link
Member

TokageItLab commented Feb 15, 2023

Confirmed, I think it is because blend_variant() is not defined for Arrays.
poly.zip

BTW 3.x is seemingly working because it uses interpolate() instead of blend(), but that calculation is incorrect.

@TokageItLab TokageItLab added this to the 4.0 milestone Feb 15, 2023
@TokageItLab TokageItLab changed the title AnimationTree erase polygons blend_variant() can't handle Array type Feb 15, 2023
@TokageItLab
Copy link
Member

Related by #66771.

@TokageItLab TokageItLab changed the title blend_variant() can't handle Array type Animation::blend_variant() can't handle Array type Feb 15, 2023
@TokageItLab TokageItLab modified the milestones: 4.0, 4.1 Feb 15, 2023
@YuriSizov YuriSizov modified the milestones: 4.1, 4.x Jun 22, 2023
@KnightNine
Copy link

KnightNine commented Jun 23, 2023

Damn, guess i'm gonna have to use frame by frame animations instead of polygon2D in 4.0. Though what software could I use for polygon animation?
Maybe blender or I can make a spritemap of my animations in 3.x.

Or I can modify godot with the code from this PR: #66771.?, that I just noticed above.

@KnightNine
Copy link

KnightNine commented Jun 26, 2023

Related by #66771.

@TokageItLab

I tried implementing the changes from that PR to my custom godot build's animation.cpp and .h files but it failed to fix this issue, am I missing something?

Confirmed, I think it is because blend_variant() is not defined for Arrays.

I've also added blend_packed_array() which the PR lacked.

ty.

@TokageItLab
Copy link
Member

That PR implement interpolate/add/sub_variant() but lacks blend_variant().

@KnightNine
Copy link

KnightNine commented Jun 26, 2023

@TokageItLab
this blend variant?

I was just translating it from the changes to interpolate_variant() so that it applies to blend_variant() so I may not have done it correctly if there's something I don't know.

@KnightNine
Copy link

KnightNine commented Jun 30, 2023

@TokageItLab

I added a couple of warn prints to animation.cpp and can now confirm that blend_variant() is being called.

case Variant::VECTOR2: {
			WARN_PRINT(vformat("v2blend.%v and %v with c: %f = %v", (a.operator Vector2()), (b.operator Vector2()),c, (a.operator Vector2()) + (b.operator Vector2()) * c ));
			return (a.operator Vector2()) + (b.operator Vector2()) * c;

and:

case Variant::PACKED_VECTOR2_ARRAY: {
					WARN_PRINT("PACKED_VECTOR2_ARRAY blend.");
					return blend_packed_array(PackedVector2Array(a), PackedVector2Array(b), c);
					

(Note: this is in the context of my scene here #75400 )

Here's a snippet of the output as the three points of the Polygon2D are transitioning between animation nodes in an animation tree:

scene\resources\animation.cpp:5725 - v2blend.(1189.000000, -374.000000) and (-733.000000, -282.000000) with c: 1.000000 = (456.000000, -656.000000)
  scene\resources\animation.cpp:5725 - v2blend.(860.000000, 117.000000) and (-585.000000, 326.000000) with c: 1.000000 = (275.000000, 443.000000)
  scene\resources\animation.cpp:5725 - v2blend.(207.000000, -196.000000) and (-1091.000000, 288.000000) with c: 1.000000 = (-884.000000, 92.000000)
  scene\resources\animation.cpp:5838 - PACKED_VECTOR2_ARRAY blend.
  scene\resources\animation.cpp:5725 - v2blend.(1189.000000, -374.000000) and (-442.000000, 628.000000) with c: 0.010346 = (1184.427124, -367.502716)
  scene\resources\animation.cpp:5725 - v2blend.(860.000000, 117.000000) and (-1415.000000, 129.000000) with c: 0.010346 = (845.360413, 118.334633)
  scene\resources\animation.cpp:5725 - v2blend.(207.000000, -196.000000) and (-336.000000, -260.000000) with c: 0.010346 = (203.523743, -198.689957)
  scene\resources\animation.cpp:5838 - PACKED_VECTOR2_ARRAY blend.
  scene\resources\animation.cpp:5725 - v2blend.(1184.427124, -367.502716) and (-733.000000, -282.000000) with c: 0.989654 = (459.010742, -646.585144)
  scene\resources\animation.cpp:5725 - v2blend.(845.360413, 118.334633) and (-585.000000, 326.000000) with c: 0.989654 = (266.412842, 440.961823)
  scene\resources\animation.cpp:5725 - v2blend.(203.523743, -198.689957) and (-1091.000000, 288.000000) with c: 0.989654 = (-876.188782, 86.330399)
  scene\resources\animation.cpp:5838 - PACKED_VECTOR2_ARRAY blend.
  scene\resources\animation.cpp:5725 - v2blend.(1189.000000, -374.000000) and (-442.000000, 628.000000) with c: 0.026264 = (1177.391357, -357.506195)
  scene\resources\animation.cpp:5725 - v2blend.(860.000000, 117.000000) and (-1415.000000, 129.000000) with c: 0.026264 = (822.836426, 120.388054)
  scene\resources\animation.cpp:5725 - v2blend.(207.000000, -196.000000) and (-336.000000, -260.000000) with c: 0.026264 = (198.175293, -202.828644)
  scene\resources\animation.cpp:5838 - PACKED_VECTOR2_ARRAY blend.
  scene\resources\animation.cpp:5725 - v2blend.(1177.391357, -357.506195) and (-733.000000, -282.000000) with c: 0.973736 = (463.642883, -632.099731)
  scene\resources\animation.cpp:5725 - v2blend.(822.836426, 120.388054) and (-585.000000, 326.000000) with c: 0.973736 = (253.200867, 437.825989)
  scene\resources\animation.cpp:5725 - v2blend.(198.175293, -202.828644) and (-1091.000000, 288.000000) with c: 0.973736 = (-864.170654, 77.607330)
  scene\resources\animation.cpp:5838 - PACKED_VECTOR2_ARRAY blend.
  scene\resources\animation.cpp:5725 - v2blend.(1189.000000, -374.000000) and (-442.000000, 628.000000) with c: 0.039752 = (1171.429565, -349.035736)
  scene\resources\animation.cpp:5725 - v2blend.(860.000000, 117.000000) and (-1415.000000, 129.000000) with c: 0.039752 = (803.750916, 122.128006)
  scene\resources\animation.cpp:5725 - v2blend.(207.000000, -196.000000) and (-336.000000, -260.000000) with c: 0.039752 = (193.643326, -206.335526)
  scene\resources\animation.cpp:5838 - PACKED_VECTOR2_ARRAY blend.
  scene\resources\animation.cpp:5725 - v2blend.(1171.429565, -349.035736) and (-733.000000, -282.000000) with c: 0.960248 = (467.567810, -619.825684)
  scene\resources\animation.cpp:5725 - v2blend.(803.750916, 122.128006) and (-585.000000, 326.000000) with c: 0.960248 = (242.005859, 435.168823)

...
(point is that you can see it should do something to the packed array)

But strangely the polygon2D's shape doesn't move at all, perhaps nothing is actually done with the returned blended array.

I found out that blend_variant() is called from animation_tree.cpp at line 1483 (t->value = Animation::blend_variant(t->value, value, blend);) though I still need to investigate why nothing is happening.

@KnightNine
Copy link

Maybe the PACKED_VECTOR2_ARRAY within the track that is pulled from TrackCacheValue *t = static_cast<TrackCacheValue *>(track); (in animation_tree.cpp) is not being passed by reference somehow.
...But that doesn't make much sense because this value fetching is used universally for all track value types which do work without issue.

I can animate packed arrays within the AnimationPlayer so maybe the AnimationPlayer is doing something the AnimationTree is not. Or I'm completely lost and it's something else entirely.💀

@KnightNine
Copy link

KnightNine commented Jun 30, 2023

WAIT , I deleted and re-created the ../Polygon:polygon animation track for my polygon2D animations, and now the polygon's PACKED_VECTOR2_ARRAY is set to a size of 0 whenever the AnimationTree is active.

So there was some sorta bug in my scene all along that may've been skewing what was supposed to happen.
Ignore the comments before about the polygon not animating, now the polygon just disappears entirely due to the packed vec2 array being emptied.

The issue here now is that Variant a within the params of blend_variant() is null:

Variant Animation::blend_variant(const Variant &a, const Variant &b, float c) {
	WARN_PRINT("now within blend_variant()");

	if (a.get_type() != b.get_type()) {
		if (a.is_num() && b.is_num()) {
			real_t va = a;
			real_t vb = b;
			return va + vb * c;
		}
		WARN_PRINT(vformat("RIP %d , %d",a.get_type(), b.get_type()));
		return a;
	}
	...

output:

  scene\animation\animation_tree.cpp:1483 - blending2
  scene\resources\animation.cpp:5705 - now within blend_variant()
  scene\resources\animation.cpp:5713 - RIP 0 , 35

Can't blend anything if the value being passed doesn't exist... what could be causing the packed array to become null?
🤔

I don't even need to start running any animations, the polygon vec2 array seems to become empty as soon as the AnimationTree becomes active.
polygon becomes null

This happens as long as there is at least one animation within the AnimationPlayer that contains a track with the continuous update_mode that has to do with the polygon's packedVec2Arr.

@KnightNine
Copy link

ok it works, but for some damned reason you need a RESET track (with continuous_update_mode and the correct array sizes) for each Packed Array being modified or else it doesn't work.
Pretty finnicky but better than nothing.

IT WORKE NAO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants