added sniffer

This commit is contained in:
Hellie-xd 2026-08-09 23:18:47 +02:00
parent 8c950a1710
commit aecb2f5d89
2 changed files with 39 additions and 0 deletions

38
classes/signal_sniffer.gd Normal file
View file

@ -0,0 +1,38 @@
extends RefCounted
class_name SignalSniffer
## Pass ANY node or object into this function, and it will print every signal it fires!
static func watch(target: Object) -> void:
print("--- [DEBUG] NOW WATCHING SIGNALS FOR: ", target.name, " ---")
# Get an array of every signal this object has (both custom and built-in)
for sig in target.get_signal_list():
var s_name = sig["name"]
# Filter out Godot's internal background noise so it doesn't spam your console
var ignored_signals = [
"script_changed", "property_list_changed",
"tree_entered", "tree_exited", "tree_exiting",
"ready", "replacing_by", "visibility_changed", "update"
]
if s_name in ignored_signals:
continue
# Find out exactly how many arguments this specific signal emits
var arg_count = sig["args"].size()
# Create a custom lambda function that perfectly matches the required argument count
match arg_count:
0: target.connect(s_name, func(): _log(s_name, target, []))
1: target.connect(s_name, func(a): _log(s_name, target, [a]))
2: target.connect(s_name, func(a, b): _log(s_name, target, [a, b]))
3: target.connect(s_name, func(a, b, c): _log(s_name, target, [a, b, c]))
4: target.connect(s_name, func(a, b, c, d): _log(s_name, target, [a, b, c, d]))
5: target.connect(s_name, func(a, b, c, d, e): _log(s_name, target, [a, b, c, d, e]))
_:
push_warning("DebugSniffer: Signal '", s_name, "' has more than 5 arguments. Add more cases!")
# The centralized print function
static func _log(signal_name: String, target:Object, args: Array) -> void:
# You can easily route this to your in-game Developer Console UI too!
print("[", target.name, "] '", signal_name, "' | Args: ", args)

View file

@ -0,0 +1 @@
uid://cjn84e7aclvmf