Skip to content

Commit

Permalink
GDScript: Allow trying to reload shallow script when instantiated
Browse files Browse the repository at this point in the history
  • Loading branch information
rune-scape committed Sep 21, 2024
1 parent e4e024a commit 5810408
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion modules/gdscript/gdscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
/* STEP 1, CREATE */

if (!valid && shallow && !reloading) {
reload(true);
}

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();
}

Expand Down
1 change: 1 addition & 0 deletions modules/gdscript/gdscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class GDScript : public Script {
bool tool = false;
bool valid = false;
bool reloading = false;
bool shallow = true;

struct MemberInfo {
int index = 0;
Expand Down
1 change: 1 addition & 0 deletions modules/gdscript/gdscript_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2645,6 +2645,7 @@ Error GDScriptCompiler::_prepare_compilation(GDScript *p_script, const GDScriptP

parsing_classes.insert(p_script);

p_script->shallow = false;
p_script->clearing = true;

p_script->native = Ref<GDScriptNativeClass>();
Expand Down

0 comments on commit 5810408

Please sign in to comment.