'How to get the property name from key?
I'm trying to get a list of all the properties and the values that are being changed from an animation player node,
but how do I get the property name of node that the animation key is changing?
maybe something like this:
var ani=aniplayer.get_animation('running');
for i in range(0,ani.get_track_count()):
var key_idx=ani.track_find_key(i,0,0);
print("property=>",ani.get_key_property(i,key_idx)," new value=>",ani.track_get_key_value(i,key_idx));
Solution 1:[1]
Let us say you have an animation player:
var aniplayer := $AnimationPlayer as AnimationPlayer
And you get an animation by name:
var ani := aniplayer.get_animation("running")
As you know you can get the number of tracks the animations has:
var track_count := ani.get_track_count()
And, of course we can loop:
for track_id in range(0,track_count):
pass
Let us see, you want to know what property is being set. To get the property, we need to get the path, and extract the property from there:
for track_id in range(0,track_count):
var track_path := (ani.track_get_path(track_id) as String).split(":")
var node_path := track_path[0]
var property_path := track_path[1]
Addendum:
There is another way to get the property path from a NodePath: get_concatenated_subnames.
Or we can get the elements separated with get_subname.
So this is the property name:
var property_path = ani.track_get_path(track_id).get_subname(0)
I guess this is good time as any to bring attention to the fact that AnimationPlayer can animate sub-properties. With get_subname(0) you get the property, but not the sub-property.
For example, you don't have to animate position, you can animate position.y and you would do that by adding :y at the end of the track name in the Animation panel. I describe how to do it with more detail elsewhere. In this case get_subname(0) will give you position, but get_concatenated_subnames() will give you position:y.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
