Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classes recursive references lead to "script could not be loaded" #27136

Closed
smedelyan opened this issue Mar 16, 2019 · 6 comments
Closed

Classes recursive references lead to "script could not be loaded" #27136

smedelyan opened this issue Mar 16, 2019 · 6 comments

Comments

@smedelyan
Copy link

smedelyan commented Mar 16, 2019

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

@akien-mga
Copy link
Member

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.

@bojidar-bg bojidar-bg changed the title Classes cross (recursive) references lead to "script could not be loaded" Classes recursive references lead to "script could not be loaded" Nov 8, 2019
@vnen
Copy link
Member

vnen commented Jan 9, 2020

Pretty much the same as #21461. Both will be solved together.

@vnen vnen added the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Jan 9, 2020
@vnen vnen modified the milestones: 3.2, 4.0 Jan 9, 2020
@Mastermori
Copy link

Mastermori commented Jan 12, 2020

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

@GaidamakUA
Copy link

What's the status on this bug?

@Calinou
Copy link
Member

Calinou commented Mar 21, 2020

@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 #21461 (comment).

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Mar 18, 2021
@Calinou
Copy link
Member

Calinou commented Sep 20, 2021

Duplicate of #21461 (same cause).

@Calinou Calinou closed this as completed Sep 20, 2021
@Calinou Calinou removed this from the 4.0 milestone Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants