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
相关产品推荐
相关产品推荐

