如何在虚幻引擎中使用 python 获取特定演员位置?

问题描述 投票:0回答:1

我在虚幻引擎 5.1 中使用 python 脚本。我正在尝试从虚幻引擎中的 python 中提取特定演员的位置 x、y、z 坐标。

我尝试使用此代码来提取位置,但它显示的是 {0, 0, 0) 结果。这段代码中cylinder_bp是UE中actor的名字。

import unreal
import torch

Assets = unreal.Actor(name='cylinder_bp').get_actor_location()

print(Assets)

输出:(圆柱实际位置为-10、-123、118)

LogPython: C:\Devanshu\RL\actors.py
LogPython: <Struct 'Vector' (0x000001C98DB5C1A0) {x: 0.000000, y: 0.000000, z: 0.000000}>

我看到了文档。我认为我正在以正确的方式做这件事。我不知道是什么问题? 请告诉我。

https://docs.unrealengine.com/4.27/zh-CN/PythonAPI/class/Actor.html#unreal.Actor

python unreal-engine4 unreal-engine5
1个回答
0
投票

以下代码在尝试从 UE4Editor 视口访问演员信息时可以正常工作:

# Enable these plugins in UE4Editor:
#   - Python Editor Script Plugin
#   - Editor Scripting Utilities
#
import unreal

actorsList = unreal.EditorLevelLibrary.get_all_level_actors()
for actor in actorsList:
    actorLabel = actor.get_actor_label()
    actorPos = actor.get_actor_location()
    if (actorLabel == 'cylinder_bp'):
        print('actorLabel= %s actorPos=%s' % (actorLabel, actorPos))
© www.soinside.com 2019 - 2024. All rights reserved.