如何在 AnimationPlayer 中获取动画中的节点?
How to get the nodes within an animation in AnimationPlayer?
我正在尝试获取受动画影响的所有节点
我知道可以通过循环曲目找到它们:
for track_indx in animation.get_track_count():
var track_node=get_node(animation.track_get_path(track_indx));
if(!list.has(track_node))
list.append(track_node);
但似乎没有必要为了获取节点而遍历所有轨道,尤其是当有太多轨道仅连接到一个节点时。
有没有更好的方法来实现这个?
没有更好的方法了。
我只是想提醒你,轨道的路径是相对于AnimationPlayer
的root_node
。您可以通过获取它们相对的节点并从中使用 get_node
来处理相对 NodePath
s:
var animation_player := get_node("AnAnimationPlayer") as AnimationPlayer
var animation := animation_player.get_animation("AnAnimation")
var root_node := animation_player.get_node(animation_player.root_node)
var list := []
for track_indx in animation.get_track_count():
var track_node := root_node.get_node(animation.track_get_path(track_indx))
if not list.has(track_node):
list.append(track_node)
for item in list:
print(item)
我正在尝试获取受动画影响的所有节点
我知道可以通过循环曲目找到它们:
for track_indx in animation.get_track_count():
var track_node=get_node(animation.track_get_path(track_indx));
if(!list.has(track_node))
list.append(track_node);
但似乎没有必要为了获取节点而遍历所有轨道,尤其是当有太多轨道仅连接到一个节点时。
有没有更好的方法来实现这个?
没有更好的方法了。
我只是想提醒你,轨道的路径是相对于AnimationPlayer
的root_node
。您可以通过获取它们相对的节点并从中使用 get_node
来处理相对 NodePath
s:
var animation_player := get_node("AnAnimationPlayer") as AnimationPlayer
var animation := animation_player.get_animation("AnAnimation")
var root_node := animation_player.get_node(animation_player.root_node)
var list := []
for track_indx in animation.get_track_count():
var track_node := root_node.get_node(animation.track_get_path(track_indx))
if not list.has(track_node):
list.append(track_node)
for item in list:
print(item)