diff --git a/core/object/object.cpp b/core/object/object.cpp index f56d31f9afb..740881a9fd3 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -1522,6 +1522,18 @@ int Object::get_persistent_signal_connection_count() const { return count; } +uint32_t Object::get_signal_connection_flags(const StringName &p_name, const Callable &p_callable) const { + OBJ_SIGNAL_LOCK + const SignalData *signal_data = signal_map.getptr(p_name); + if (signal_data) { + const SignalData::Slot *slot = signal_data->slot_map.getptr(p_callable); + if (slot) { + return slot->conn.flags; + } + } + return 0; +} + void Object::get_signals_connected_to_this(List *p_connections) const { OBJ_SIGNAL_LOCK diff --git a/core/object/object.h b/core/object/object.h index 1fa64e68556..a026d277011 100644 --- a/core/object/object.h +++ b/core/object/object.h @@ -973,6 +973,7 @@ public: DEBUG_VIRTUAL void get_signal_connection_list(const StringName &p_signal, List *p_connections) const; DEBUG_VIRTUAL void get_all_signal_connections(List *p_connections) const; DEBUG_VIRTUAL int get_persistent_signal_connection_count() const; + DEBUG_VIRTUAL uint32_t get_signal_connection_flags(const StringName &p_name, const Callable &p_callable) const; DEBUG_VIRTUAL void get_signals_connected_to_this(List *p_connections) const; DEBUG_VIRTUAL Error connect(const StringName &p_signal, const Callable &p_callable, uint32_t p_flags = 0); diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 5db915c58a8..dbd790c6269 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -4191,6 +4191,11 @@ int Node::get_persistent_signal_connection_count() const { return Object::get_persistent_signal_connection_count(); } +uint32_t Node::get_signal_connection_flags(const StringName &p_signal, const Callable &p_callable) const { + ERR_THREAD_GUARD_V(0); + return Object::get_signal_connection_flags(p_signal, p_callable); +} + void Node::get_signals_connected_to_this(List *p_connections) const { ERR_THREAD_GUARD; Object::get_signals_connected_to_this(p_connections); @@ -4214,14 +4219,13 @@ void Node::disconnect(const StringName &p_signal, const Callable &p_callable) { #ifdef TOOLS_ENABLED // Already under thread guard, don't check again. - int old_connection_count = Object::get_persistent_signal_connection_count(); + uint32_t connection_flags = Object::get_signal_connection_flags(p_signal, p_callable); #endif - Object::disconnect(p_signal, p_callable); + [[maybe_unused]] bool changed = Object::_disconnect(p_signal, p_callable); #ifdef TOOLS_ENABLED - int new_connection_count = Object::get_persistent_signal_connection_count(); - if (old_connection_count != new_connection_count) { + if (changed && connection_flags & CONNECT_PERSIST) { _emit_editor_state_changed(); } #endif diff --git a/scene/main/node.h b/scene/main/node.h index 974a6b5b54d..8f3939046d0 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -875,6 +875,7 @@ public: virtual void get_signal_connection_list(const StringName &p_signal, List *p_connections) const override; virtual void get_all_signal_connections(List *p_connections) const override; virtual int get_persistent_signal_connection_count() const override; + virtual uint32_t get_signal_connection_flags(const StringName &p_name, const Callable &p_callable) const override; virtual void get_signals_connected_to_this(List *p_connections) const override; virtual Error connect(const StringName &p_signal, const Callable &p_callable, uint32_t p_flags = 0) override;