39 lines
1.7 KiB
GDScript3
39 lines
1.7 KiB
GDScript3
|
|
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)
|