Godot version: 3.1
OS/device including version: Ubuntu 18.04
Issue description:
Say, you have the following:
# one.gd
extends Node2D
class_name One
func use_two(var two: Two):
pass
# two.gd
extends Node
class_name Two
func use_one(var one: One):
pass
The project will fail on startup with error "Class 'One' was found in global scope but its script could not be loaded"
If we remove one of type annotations : One
or : Two
from functions above, it will launch without any complaint
Note: same behavior was discovered for case when we replace class_name
-s with preload
logic, but the message is slightly different (something about recursive references)
Minimal reproduction project:
repro_recursive.tar.gz
Partial duplicate of #21461, but that issue is long and confusing, so it's probably best to keep this new one to focus on the class_name
cross-referencing issue.
Note: same behavior was discovered for case when we replace
class_name
-s withpreload
logic, but the message is slightly different (something about recursive references)
That one is expected, preload
involves loading the whole script, and thus resolving all its dependencies, leading to recursive references. But for class_name
, it should be solvable somehow with a system akin to forward declares.
Pretty much the same as #21461. Both will be solved together.
This bug is also present when a class references a class which preloads the other class.
So
# one.gd
extends Node
class_name One
var two = preload("res://two.gd")
# two.gd
extends Node
func use_one(one : One);
pass
fails to execute with the same error.
Edit: fixed formatting
What's the status on this bug?
@GaidamakUA @vnen has started working on a GDScript refactor which will eliminate this issue. It should be finished by the time Godot 4.0 is released. See https://github.com/godotengine/godot/issues/21461#issuecomment-578860188.
Most helpful comment
@GaidamakUA @vnen has started working on a GDScript refactor which will eliminate this issue. It should be finished by the time Godot 4.0 is released. See https://github.com/godotengine/godot/issues/21461#issuecomment-578860188.