如何在AnimationPlayer中获取动画中的节点?

发布于 2025-01-14 23:47:35 字数 470 浏览 4 评论 0原文

我试图获取受动画影响的所有节点

在此处输入图像描述

我知道可以通过循环轨道找到它们:

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);

但似乎没有必要为了获取节点而迭代所有轨道,尤其是当有仅一个节点附加了太多轨道。

有更好的方法来实现这一目标吗?

I'm trying to get all the nodes which are effected by an animation

enter image description here

I know that it's possible to find them through looping tracks:

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);

but it seems unnecessary iterating over all the tracks just to get the nodes, especially when there are too many tracks attached to just one node.

Is there a better way to achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北笙凉宸 2025-01-21 23:47:35

没有更好的方法了。


我只是想提醒您,轨道的路径是相对于AnimationPlayerroot_node的。您可以通过获取相对于它们的节点并从中使用 get_node 来处理相对的 NodePath:

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)

There isn't a better way.


I just want to remind you that the paths of tracks are relative to the root_node of the AnimationPlayer. You can deal with relative NodePaths by getting the node they are relative to, and using get_node from it:

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文