Browse Source

Fix resources being skipped in InstancePlaceholder

matheusmdx 1 year ago
parent
commit
260c05152d
1 changed files with 9 additions and 6 deletions
  1. 9 6
      scene/main/instance_placeholder.cpp

+ 9 - 6
scene/main/instance_placeholder.cpp

@@ -161,12 +161,12 @@ void InstancePlaceholder::set_value_on_instance(InstancePlaceholder *p_placehold
 	}
 
 	switch (current_type) {
-		case Variant::Type::NIL:
-			if (placeholder_type != Variant::Type::NODE_PATH) {
+		case Variant::Type::NIL: {
+			Ref<Resource> resource = p_set.value;
+			if (placeholder_type != Variant::Type::NODE_PATH && !resource.is_valid()) {
 				break;
 			}
-			// If it's nil but we have a NodePath, we guess what works.
-
+			// If it's nil but we have a NodePath or a Resource, we guess what works.
 			p_instance->set(p_set.name, p_set.value, &is_valid);
 			if (is_valid) {
 				break;
@@ -174,13 +174,15 @@ void InstancePlaceholder::set_value_on_instance(InstancePlaceholder *p_placehold
 
 			p_instance->set(p_set.name, try_get_node(p_placeholder, p_instance, p_set.value), &is_valid);
 			break;
-		case Variant::Type::OBJECT:
+		}
+		case Variant::Type::OBJECT: {
 			if (placeholder_type != Variant::Type::NODE_PATH) {
 				break;
 			}
 			// Easiest case, we want a node, but we have a deferred NodePath.
 			p_instance->set(p_set.name, try_get_node(p_placeholder, p_instance, p_set.value));
 			break;
+		}
 		case Variant::Type::ARRAY: {
 			// If we have reached here it means our array types don't match,
 			// so we will convert the placeholder array into the correct type
@@ -209,9 +211,10 @@ void InstancePlaceholder::set_value_on_instance(InstancePlaceholder *p_placehold
 			}
 			break;
 		}
-		default:
+		default: {
 			WARN_PRINT(vformat("Property '%s' with type '%s' could not be set when creating instance of '%s'.", p_set.name, Variant::get_type_name(current_type), p_placeholder->get_name()));
 			break;
+		}
 	}
 }