GDScript: Allow trying to reload shallow script when instantiated

This commit is contained in:
rune-scape 2024-09-21 12:58:36 -07:00
parent e4e024ab88
commit 1a5ec83fcc
3 changed files with 8 additions and 1 deletions

View file

@ -205,8 +205,13 @@ GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argco
Variant GDScript::_new(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { Variant GDScript::_new(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
/* STEP 1, CREATE */ /* STEP 1, CREATE */
if (!valid && shallow && !reloading && is_root_script()) {
reload(true);
}
if (!valid) { if (!valid) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; ERR_FAIL_COND_V_MSG(!valid, Variant(), "Can't instantiate invalid script.");
r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL;
return Variant(); return Variant();
} }

View file

@ -63,6 +63,7 @@ class GDScript : public Script {
bool tool = false; bool tool = false;
bool valid = false; bool valid = false;
bool reloading = false; bool reloading = false;
bool shallow = true;
struct MemberInfo { struct MemberInfo {
int index = 0; int index = 0;

View file

@ -2645,6 +2645,7 @@ Error GDScriptCompiler::_prepare_compilation(GDScript *p_script, const GDScriptP
parsing_classes.insert(p_script); parsing_classes.insert(p_script);
p_script->shallow = false;
p_script->clearing = true; p_script->clearing = true;
p_script->native = Ref<GDScriptNativeClass>(); p_script->native = Ref<GDScriptNativeClass>();