Przeglądaj źródła

Fix editor-only visibility for lights

* Update visibility again for editor-only lights if owner changes.

Fixes #26399, supersedes #52327

(cherry picked from commit d69e3791bf41dca6c29a9eb24bb92648cce2d692)
reduz 3 lat temu
rodzic
commit
995281ca90

+ 5 - 0
scene/2d/light_2d.cpp

@@ -81,6 +81,11 @@ Rect2 Light2D::get_anchorable_rect() const {
 	return Rect2(texture_offset - s / 2.0, s);
 }
 
+void Light2D::owner_changed_notify() {
+	// For cases where owner changes _after_ entering tree (as example, editor editing).
+	_update_light_visibility();
+}
+
 void Light2D::_update_light_visibility() {
 	if (!is_inside_tree()) {
 		return;

+ 2 - 0
scene/2d/light_2d.h

@@ -79,6 +79,8 @@ private:
 
 	void _update_light_visibility();
 
+	virtual void owner_changed_notify();
+
 protected:
 	void _notification(int p_what);
 	static void _bind_methods();

+ 5 - 0
scene/3d/light.cpp

@@ -144,6 +144,11 @@ Light::BakeMode Light::get_bake_mode() const {
 	return bake_mode;
 }
 
+void Light::owner_changed_notify() {
+	// For cases where owner changes _after_ entering tree (as example, editor editing).
+	_update_visibility();
+}
+
 void Light::_update_visibility() {
 	if (!is_inside_tree()) {
 		return;

+ 2 - 0
scene/3d/light.h

@@ -81,6 +81,8 @@ private:
 
 	// bind helpers
 
+	virtual void owner_changed_notify();
+
 protected:
 	RID light;
 

+ 5 - 0
scene/main/node.cpp

@@ -458,6 +458,9 @@ void Node::move_child_notify(Node *p_child) {
 	// to be used when not wanted
 }
 
+void Node::owner_changed_notify() {
+}
+
 void Node::_physics_interpolated_changed() {}
 
 void Node::set_physics_process(bool p_process) {
@@ -1605,6 +1608,8 @@ void Node::_set_owner_nocheck(Node *p_owner) {
 	data.owner = p_owner;
 	data.owner->data.owned.push_back(this);
 	data.OW = data.owner->data.owned.back();
+
+	owner_changed_notify();
 }
 
 void Node::_release_unique_name_in_owner() {

+ 1 - 0
scene/main/node.h

@@ -236,6 +236,7 @@ protected:
 	virtual void add_child_notify(Node *p_child);
 	virtual void remove_child_notify(Node *p_child);
 	virtual void move_child_notify(Node *p_child);
+	virtual void owner_changed_notify();
 
 	virtual void _physics_interpolated_changed();