Godot: Classes recursive references lead to "script could not be loaded"

Created on 16 Mar 2019  路  5Comments  路  Source: godotengine/godot

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

bug 3.2 gdscript

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.

All 5 comments

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 with preload 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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SleepProgger picture SleepProgger  路  3Comments

ndee85 picture ndee85  路  3Comments

bojidar-bg picture bojidar-bg  路  3Comments

testman42 picture testman42  路  3Comments

n-pigeon picture n-pigeon  路  3Comments