@@ -52,4 +52,59 @@ func erase_value(key: Variant, blackboard_name: String = DEFAULT) -> void:
5252 _data [blackboard_name ][key ] = null
5353
5454func get_debug_data () -> Dictionary :
55- return _data
55+ # Avoid sending raw Objects (Nodes, Resources, etc.) over the
56+ # EngineDebugger connection, which can cause Variant marshalling errors
57+ # and break the editor debugger stream.
58+ return _sanitize_for_debug (_data )
59+
60+
61+ static func _sanitize_for_debug (value : Variant , depth : int = 0 ) -> Variant :
62+ # Limit recursion depth defensively to avoid issues with deeply nested
63+ # or self‑referential data structures. At this point we only need a
64+ # human‑readable representation for the debugger UI.
65+ if depth > 4 :
66+ return str (value )
67+
68+ var t := typeof (value )
69+
70+ match t :
71+ TYPE_DICTIONARY :
72+ var result := {}
73+ for key in value .keys ():
74+ var safe_key := _sanitize_for_debug (key , depth + 1 )
75+ var safe_val := _sanitize_for_debug (value [key ], depth + 1 )
76+ result [safe_key ] = safe_val
77+ return result
78+
79+ TYPE_ARRAY :
80+ var arr : Array = []
81+ for v in value :
82+ arr .append (_sanitize_for_debug (v , depth + 1 ))
83+ return arr
84+
85+ TYPE_OBJECT :
86+ if value == null :
87+ return null
88+
89+ if value is Node :
90+ var path := ""
91+ if value .get_tree ():
92+ path = str (value .get_path ())
93+ return {
94+ "type" : value .get_class (),
95+ "name" : value .name ,
96+ "path" : path ,
97+ "id" : value .get_instance_id (),
98+ }
99+
100+ if value is Resource :
101+ return {
102+ "type" : value .get_class (),
103+ "resource_path" : value .resource_path ,
104+ }
105+
106+ # Fallback: string representation is enough for the debugger.
107+ return str (value )
108+
109+ _ :
110+ return value
0 commit comments