Browse Source

Allow VisibleOnScreenNotifier2D/3D to have empty `enable_node_path`

Micky 1 năm trước cách đây
mục cha
commit
445b1e9c5f

+ 1 - 1
doc/classes/VisibleOnScreenEnabler2D.xml

@@ -15,7 +15,7 @@
 			Determines how the target node is enabled. Corresponds to [enum Node.ProcessMode]. When the node is disabled, it always uses [constant Node.PROCESS_MODE_DISABLED].
 			Determines how the target node is enabled. Corresponds to [enum Node.ProcessMode]. When the node is disabled, it always uses [constant Node.PROCESS_MODE_DISABLED].
 		</member>
 		</member>
 		<member name="enable_node_path" type="NodePath" setter="set_enable_node_path" getter="get_enable_node_path" default="NodePath(&quot;..&quot;)">
 		<member name="enable_node_path" type="NodePath" setter="set_enable_node_path" getter="get_enable_node_path" default="NodePath(&quot;..&quot;)">
-			The path to the target node, relative to the [VisibleOnScreenEnabler2D]. The target node is cached; it's only assigned when setting this property (if the [VisibleOnScreenEnabler2D] is inside the scene tree) and every time the [VisibleOnScreenEnabler2D] enters the scene tree. If the path is invalid, an error will be printed in the editor and no node will be affected.
+			The path to the target node, relative to the [VisibleOnScreenEnabler2D]. The target node is cached; it's only assigned when setting this property (if the [VisibleOnScreenEnabler2D] is inside the scene tree) and every time the [VisibleOnScreenEnabler2D] enters the scene tree. If the path is empty, no node will be affected. If the path is invalid, an error is also generated.
 		</member>
 		</member>
 	</members>
 	</members>
 	<constants>
 	<constants>

+ 1 - 1
doc/classes/VisibleOnScreenEnabler3D.xml

@@ -15,7 +15,7 @@
 			Determines how the target node is enabled. Corresponds to [enum Node.ProcessMode]. When the node is disabled, it always uses [constant Node.PROCESS_MODE_DISABLED].
 			Determines how the target node is enabled. Corresponds to [enum Node.ProcessMode]. When the node is disabled, it always uses [constant Node.PROCESS_MODE_DISABLED].
 		</member>
 		</member>
 		<member name="enable_node_path" type="NodePath" setter="set_enable_node_path" getter="get_enable_node_path" default="NodePath(&quot;..&quot;)">
 		<member name="enable_node_path" type="NodePath" setter="set_enable_node_path" getter="get_enable_node_path" default="NodePath(&quot;..&quot;)">
-			The path to the target node, relative to the [VisibleOnScreenEnabler3D]. The target node is cached; it's only assigned when setting this property (if the [VisibleOnScreenEnabler3D] is inside the scene tree) and every time the [VisibleOnScreenEnabler3D] enters the scene tree. If the path is invalid, an error will be printed in the editor and no node will be affected.
+			The path to the target node, relative to the [VisibleOnScreenEnabler3D]. The target node is cached; it's only assigned when setting this property (if the [VisibleOnScreenEnabler3D] is inside the scene tree) and every time the [VisibleOnScreenEnabler3D] enters the scene tree. If the path is empty, no node will be affected. If the path is invalid, an error is also generated.
 		</member>
 		</member>
 	</members>
 	</members>
 	<constants>
 	<constants>

+ 8 - 1
scene/2d/visible_on_screen_notifier_2d.cpp

@@ -138,6 +138,10 @@ void VisibleOnScreenEnabler2D::set_enable_node_path(NodePath p_path) {
 		return;
 		return;
 	}
 	}
 	enable_node_path = p_path;
 	enable_node_path = p_path;
+	if (enable_node_path.is_empty()) {
+		node_id = ObjectID();
+		return;
+	}
 	if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
 	if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
 		node_id = ObjectID();
 		node_id = ObjectID();
 		Node *node = get_node(enable_node_path);
 		Node *node = get_node(enable_node_path);
@@ -177,8 +181,11 @@ void VisibleOnScreenEnabler2D::_notification(int p_what) {
 			if (Engine::get_singleton()->is_editor_hint()) {
 			if (Engine::get_singleton()->is_editor_hint()) {
 				return;
 				return;
 			}
 			}
-
 			node_id = ObjectID();
 			node_id = ObjectID();
+			if (enable_node_path.is_empty()) {
+				return;
+			}
+
 			Node *node = get_node(enable_node_path);
 			Node *node = get_node(enable_node_path);
 			if (node) {
 			if (node) {
 				node_id = node->get_instance_id();
 				node_id = node->get_instance_id();

+ 8 - 1
scene/3d/visible_on_screen_notifier_3d.cpp

@@ -138,6 +138,10 @@ void VisibleOnScreenEnabler3D::set_enable_node_path(NodePath p_path) {
 		return;
 		return;
 	}
 	}
 	enable_node_path = p_path;
 	enable_node_path = p_path;
+	if (enable_node_path.is_empty()) {
+		node_id = ObjectID();
+		return;
+	}
 	if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
 	if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
 		node_id = ObjectID();
 		node_id = ObjectID();
 		Node *node = get_node(enable_node_path);
 		Node *node = get_node(enable_node_path);
@@ -177,8 +181,11 @@ void VisibleOnScreenEnabler3D::_notification(int p_what) {
 			if (Engine::get_singleton()->is_editor_hint()) {
 			if (Engine::get_singleton()->is_editor_hint()) {
 				return;
 				return;
 			}
 			}
-
 			node_id = ObjectID();
 			node_id = ObjectID();
+			if (enable_node_path.is_empty()) {
+				return;
+			}
+
 			Node *node = get_node(enable_node_path);
 			Node *node = get_node(enable_node_path);
 			if (node) {
 			if (node) {
 				node_id = node->get_instance_id();
 				node_id = node->get_instance_id();