You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unreal Engine 5.1 Python获取指定Actor位置返回(0,0,0)问题求助

问题原因

你直接通过unreal.Actor(name='cylinder_bp')创建的是一个新的Actor类实例,并非场景中已经存在的名为cylinder_bp的Actor对象,这类未被放置到关卡中的Actor默认位置就是(0,0,0)。

解决方案

要获取场景中已存在的Actor,需要使用Unreal的编辑器工具函数来查找:

方法1:遍历关卡所有Actor查找

import unreal

# 获取关卡内所有Actor
all_actors = unreal.EditorLevelLibrary.get_all_level_actors()
target_actor = None

# 遍历匹配目标Actor名称
for actor in all_actors:
    if actor.get_name() == "cylinder_bp":
        target_actor = actor
        break

if target_actor:
    location = target_actor.get_actor_location()
    print(f"Actor位置:x={location.x}, y={location.y}, z={location.z}")
else:
    print("未找到名为cylinder_bp的Actor")

方法2:通过编辑器子系统精准查找

import unreal

# 获取编辑器Actor子系统
actor_subsystem = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)
# 按名称查找Actor(重名时返回第一个匹配项)
target_actor = actor_subsystem.find_actor_by_name("cylinder_bp")

if target_actor:
    location = target_actor.get_actor_location()
    print(f"Actor位置:x={location.x}, y={location.y}, z={location.z}")
else:
    print("未找到名为cylinder_bp的Actor")
补充提示
  • 确认cylinder_bp是场景中Actor的显示名称(可在细节面板查看),而非蓝图资产的名称;
  • 若Actor是蓝图实例化生成,名称可能带有后缀(如cylinder_bp_0),需核对准确名称后再查找。

内容的提问来源于stack exchange,提问作者Devanshu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 14:17:05