diff options
author | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2016-06-09 16:24:12 +0200 |
---|---|---|
committer | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2016-06-09 16:47:34 +0200 |
commit | dc2ea39f242979f69be3469bea8ef2467ab98b34 (patch) | |
tree | d14af888a361b2463f3a07c32d5df1291df94821 /scene/main | |
parent | 9f94d3fbace543bb723b49d3a3a7d97e0da65f41 (diff) |
Preserve signal connections when replacing the target node
Diffstat (limited to 'scene/main')
-rw-r--r-- | scene/main/node.cpp | 16 | ||||
-rw-r--r-- | scene/main/node.h | 2 |
2 files changed, 17 insertions, 1 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp index f8af83e23b..cfc7116d19 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -1770,6 +1770,8 @@ void Node::replace_by(Node* p_node,bool p_keep_data) { } } + _replace_connections_target(p_node); + if (data.owner) { for(int i=0;i<get_child_count();i++) find_owned_by(data.owner,get_child(i),&owned_by_owner); @@ -1808,6 +1810,20 @@ void Node::replace_by(Node* p_node,bool p_keep_data) { } +void Node::_replace_connections_target(Node* p_new_target) { + + List<Connection> cl; + get_signals_connected_to_this(&cl); + + for(List<Connection>::Element *E=cl.front();E;E=E->next()) { + + Connection &c=E->get(); + + c.source->disconnect(c.signal,this,c.method); + c.source->connect(c.signal,p_new_target,c.method,c.binds,c.flags); + } +} + Vector<Variant> Node::make_binds(VARIANT_ARG_DECLARE) { diff --git a/scene/main/node.h b/scene/main/node.h index d099f6e773..a3b8d8de81 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -121,7 +121,7 @@ private: Node *_get_node(const NodePath& p_path) const; Node *_get_child_by_name(const StringName& p_name) const; - + void _replace_connections_target(Node* p_new_target); void _validate_child_name(Node *p_name, bool p_force_human_readable=false); |