0 votes

I'm trying edit an Animation resource via GDScript, but everything I do spits errors.

This is basically the code I'm using:

track_index = animation.add_track(animation.TYPE_VALUE)
animation.track_insert_key(track_index, 0.0, i.modulate)

But when running, said code prints this error multiple times:

0:00:02:0661 - Condition ' !data ' is true. returned: StringName()
Time: 0:00:02:0661
C Error: Condition ' !data ' is true. returned: StringName()
C Source: core/node_path.cpp:204
C Function: get_concatenated_subnames
in Engine by (81 points)

1 Answer

0 votes

I haven't gotten around to porting this code to 3.0 yet but here is some 2.x code. I'm not sure how good of an idea this is, but I have a scene that has an animation defined in it. To make it reusable I add it to an object that I want to have said animation. I then update the animation so it is wired to the new object instead. This is the code I use to update the animation. This is 2.x code, so the :transform/scale etc will be different in 3.0

onready var _player = get_node('AnimationPlayer')


var anim = _player.get_animation(ANIM_PHASE_OUT)
anim.track_set_path(0, new_sprite_path + ':transform/scale')
anim.track_set_path(1, new_sprite_path + ':visibility/visible')

var anim = _player.get_animation(ANIM_PHASE)
anim.track_set_path(0, new_sprite_path + ':transform/scale')

This allowed me to work in a scene, creating the animation the way I wanted and then apply it to any object I wanted. The code to update the animation went in the script for the scene that had the animation. So I just add the animation scene as a child to a scene and then call the method to wire it up by passing in new_sprite_path.

This could be a really bad practice but it worked great for applying the animation to a lot of different kinds of objects.

by (143 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.