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

Cannot change texture property of a Sprite2D Node using animation tracks in GDScript #88579

Closed
codyroberts opened this issue Feb 20, 2024 · 2 comments · Fixed by #88661
Closed

Comments

@codyroberts
Copy link

codyroberts commented Feb 20, 2024

Tested versions

Reproducible in v4.2.1.stable.official.b09f793f5

Attempted to reproduce in v3.5.3.stable.mono.official but not confident I could create an equivalent example, however in what I did attempt the feature still did not work.

System information

Windows 10

Issue description

When attempting to create an animation entirely in GDScript using an existing image, the texture cannot be animated. Attempting to animate the texture appears to cause the Sprite2D to have no texture, being invisible upon debugging.

Steps to reproduce

  1. Create a Node2D node
  2. Add a Sprite2D child node, and assign it a texture using the Inspector GUI
  3. Set up an animation on the Node2D node to change the texture of the Sprite2D node similar to the provided sample script below
extends Node2D

# Create the animation player and library
@onready var animation_player := AnimationPlayer.new()
@onready var animation_library := AnimationLibrary.new()

# Called when the node enters the scene tree for the first time.
func _ready():
	
	# Add the animation player as a child of the node
	add_child(animation_player)
	
	# Load the new icon texture
	var texture: Texture2D = load("res://new_icon.svg")
	
	# Declare a new animation
	var new_animation = Animation.new()
	
	# Declare the animation track
	var texture_track = new_animation.add_track(Animation.TYPE_VALUE)
	
	# Set the track path to target the Sprite2D's texture property
	new_animation.track_set_path(texture_track, "Sprite2D:texture")
	
	# Insert a key to change the texture to the new icon
	new_animation.track_insert_key(texture_track, 0, texture)
	
	# Add the animation to the library
	animation_library.add_animation("change_texture", new_animation)
	
	# Add the library to the animation player
	animation_player.add_animation_library("", animation_library)
	


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
	
	# Play the animation
	animation_player.play("change_texture")

Minimal reproduction project (MRP)

GDScriptTextureAnimation.zip

@kleonc
Copy link
Member

kleonc commented Feb 20, 2024

Happens since v4.2.dev6.official [57a6813].
Probably a regression from #80813? cc @TokageItLab

@akien-mga akien-mga added this to the 4.3 milestone Feb 20, 2024
@TokageItLab
Copy link
Member

I guess it could be that for some reason the type determination fails and the value key type is determined to be Nil, causing the interpolation to fail, but I'd have to look into the details.

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.

4 participants