Merge pull request #94345 from matheusmdx/fix-instance-placeholder-with-resource

Fix resources being skipped in InstancePlaceholder
This commit is contained in:
Rémi Verschelde 2024-07-17 15:45:00 +02:00
commit e7b624567d
No known key found for this signature in database
GPG key ID: C3336907360768E1

View file

@ -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;
}
}
}