Skip to content

Commit d7c4773

Browse files
committed
Merge pull request #109903 from aaronfranke/abstract-rugpull
Allow extending previously-non-abstract scripts that became abstract
2 parents b86d05e + 84eb90b commit d7c4773

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

scene/resources/packed_scene.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,24 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const {
347347
node->get_script_instance()->get_property_state(old_state);
348348
}
349349

350-
node->set(snames[nprops[j].name], props[nprops[j].value], &valid);
350+
#ifdef TOOLS_ENABLED
351+
const Ref<Script> value_as_script = props[nprops[j].value];
352+
// It is possible that the user changed an existing script to abstract after it was attached to a node.
353+
// When this happens, the user needs to fix it. See https://github.com/godotengine/godot/issues/109171
354+
if (value_as_script.is_valid() && value_as_script->is_abstract()) {
355+
const String global_class_name = value_as_script->get_global_name();
356+
if (global_class_name.is_empty()) {
357+
ERR_PRINT("Node \"" + snames[n.name] + "\" previously had a script, but that script is now abstract. Please assign a different script (right-click -> Attach Script...) or change the node to a different type (right-click -> Change Type...) to fix this, then re-save the scene.");
358+
} else {
359+
ERR_PRINT("Node \"" + snames[n.name] + "\" previously had a class of type \"" + global_class_name + "\", but that class is now abstract. Please assign a different script (right-click -> Attach Script...) or change the node to a different type (right-click -> Change Type...) to fix this, then re-save the scene.");
360+
}
361+
callable_mp((Object *)node, &Object::remove_meta).call_deferred(SceneStringName(_custom_type_script));
362+
} else {
363+
node->set_script(props[nprops[j].value]);
364+
}
365+
#else
366+
node->set_script(props[nprops[j].value]);
367+
#endif // TOOLS_ENABLED
351368

352369
//restore old state for new script, if exists
353370
for (const Pair<StringName, Variant> &E : old_state) {

0 commit comments

Comments
 (0)