Skip to content

GDScript reload generates error when created dynamically (no backing script) #65263

@bitwes

Description

@bitwes

Godot version

v4.0.alpha15.official.432b25d36

System information

OSX 10.15.7

Issue description

When you create a GDScript object, set the source, and then call reload it generates the following error:

ERROR: Attempt to open script '' resulted in error 'File not found'.
   at: load_source_code (modules/gdscript/gdscript.cpp:1064)

Steps to reproduce

This script creates a simple GDScript from a string of source code, creates an instance and calls a method on it.

extends SceneTree

func _init():
	var script_source = '' + \
	"func hello_world():\n" + \
	"\tprint('--- hello world ---')"

	print(script_source)

	var DynScript = GDScript.new()
	DynScript.source_code = script_source
	print('pre-reload')
	DynScript.reload()
	print('post-reload')

	var inst = DynScript.new()
	inst.hello_world()

	quit()

The output shows the error occurs on the reload call.

Godot Engine v4.0.alpha15.official.432b25d36 - https://godotengine.org
Vulkan API 1.1.216 - Using Vulkan Device #0: AMD - AMD Radeon Pro 450
 
Registered camera FaceTime HD Camera (Built-in) with id 1 position 0 at index 0
func hello_world():
        print('--- hello world ---')
pre-reload
ERROR: Attempt to open script '' resulted in error 'File not found'.
   at: load_source_code (modules/gdscript/gdscript.cpp:1064)
post-reload
--- hello world ---

Minimal reproduction project

See steps to reproduce

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions