Files
ChildHood/tools/asset-catalog/probe_trace_v2.py
T
starmen1265 9f6572600b feat(tools): 添加UE5资产探索脚本系统asset-catalog
- discover_assets: 枚举Content资产,按UE5类型分类,输出index.json
- analyze_meshes: 包围盒/锚点/bbox_faces(area+orientation)/Line Trace细节包围盒/规则Tags
- analyze_materials: 动态参数提取/base_color_hex自动转换/规则Tags
- analyze_blueprints: generated_class API Actor检测/组件提取/interaction推断Tags
- run_all编排器: 断点续跑/步骤控制/错误traceback/UE5 JSON序列化兼容
- probe脚本: UE5.7 API探测(TraceTypeQuery/DrawDebugTrace枚举发现)
2026-06-09 19:01:50 +08:00

103 lines
3.1 KiB
Python

"""UE5 Line Trace API 精确探测。"""
import unreal
print("=" * 60)
print("Line Trace API Probe v2")
print("=" * 60)
# Spawn test cube
mesh = unreal.load_asset("/Game/BlockingStarterPack/Meshes/Primitives/SM_Cube.SM_Cube")
subsys = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)
actor = subsys.spawn_actor_from_object(mesh, unreal.Vector(0, 0, 0))
trace_ch = unreal.TraceTypeQuery.TRACE_TYPE_QUERY1
print(f"trace_channel = {trace_ch} (type: {type(trace_ch).__name__})")
# 1. Find draw_debug_type enum
print("\n--- Find draw_debug_type ---")
for name in ['EDrawDebugTrace', 'DrawDebugTrace']:
try:
enum_cls = getattr(unreal, name)
print(f" unreal.{name} found: {dir(enum_cls)}")
none_val = enum_cls.NONE
print(f" {name}.NONE = {none_val}")
break
except AttributeError:
print(f" unreal.{name}: not found")
# 2. Test line_trace_single with correct enum
print("\n--- Test line_trace_single ---")
try:
draw_debug = unreal.EDrawDebugTrace.NONE
except AttributeError:
draw_debug = None
# Attempt 1: 7 args with draw_debug
print(f" Attempt 1: 7 args, draw_debug={draw_debug}")
try:
hit = unreal.SystemLibrary.line_trace_single(
actor,
unreal.Vector(50, 50, 200),
unreal.Vector(50, 50, -200),
trace_ch,
False, [], draw_debug,
)
print(f" HIT: {hit}")
if hit and hasattr(hit, 'impact_point'):
print(f" impact: ({hit.impact_point.x},{hit.impact_point.y},{hit.impact_point.z})")
except Exception as e:
print(f" FAIL: {e}")
# Attempt 2: try line_trace_single_new
print(f" Attempt 2: line_trace_single_new")
try:
hit = unreal.SystemLibrary.line_trace_single_new(
actor,
unreal.Vector(50, 50, 200),
unreal.Vector(50, 50, -200),
trace_ch,
False, [],
)
print(f" HIT: {hit}")
if hit and hasattr(hit, 'impact_point'):
print(f" impact: ({hit.impact_point.x},{hit.impact_point.y},{hit.impact_point.z})")
except Exception as e:
print(f" FAIL: {e}")
# Attempt 3: line_trace_single_for_objects
print(f" Attempt 3: line_trace_single_for_objects")
try:
hit = unreal.SystemLibrary.line_trace_single_for_objects(
actor,
unreal.Vector(50, 50, 200),
unreal.Vector(50, 50, -200),
[unreal.ObjectTypeQuery1],
False, [], draw_debug,
)
print(f" HIT: {hit}")
except Exception as e:
print(f" FAIL: {e}")
# Attempt 4: line_trace_single_by_profile
print(f" Attempt 4: line_trace_single_by_profile")
try:
hit = unreal.SystemLibrary.line_trace_single_by_profile(
actor,
unreal.Vector(50, 50, 200),
unreal.Vector(50, 50, -200),
"Visibility",
False, [],
)
print(f" HIT: {hit}")
if hit and hasattr(hit, 'impact_point'):
print(f" impact: ({hit.impact_point.x},{hit.impact_point.y},{hit.impact_point.z})")
except Exception as e:
print(f" FAIL: {e}")
# Cleanup
unreal.EditorLevelLibrary.destroy_actor(actor)
print("\n" + "=" * 60)
print("Done.")
unreal.SystemLibrary.execute_console_command(None, "quit")