From 203d3be200c9b607e5eaba82d9a267813a6700cd Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Thu, 18 Jan 2024 17:20:56 +0100 Subject: [PATCH] [Core] Add way to check if a signal has any connections Added to `Object` and `Signal` --- core/object/object.cpp | 19 +++++++++++++++++++ core/object/object.h | 1 + core/variant/callable.cpp | 7 +++++++ core/variant/callable.h | 1 + core/variant/variant_call.cpp | 1 + doc/classes/Object.xml | 8 ++++++++ doc/classes/Signal.xml | 6 ++++++ scene/main/node.cpp | 5 +++++ scene/main/node.h | 1 + 9 files changed, 49 insertions(+) diff --git a/core/object/object.cpp b/core/object/object.cpp index 2d9d468d388..b3a4ec6e2ed 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -1457,6 +1457,24 @@ bool Object::is_connected(const StringName &p_signal, const Callable &p_callable return s->slot_map.has(*p_callable.get_base_comparator()); } +bool Object::has_connections(const StringName &p_signal) const { + const SignalData *s = signal_map.getptr(p_signal); + if (!s) { + bool signal_is_valid = ClassDB::has_signal(get_class_name(), p_signal); + if (signal_is_valid) { + return false; + } + + if (!script.is_null() && Ref