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