godot: class_name: "Class '_' could not be fully loaded"
Godot version: 3.1 Alpha
OS/device including version: Windows 10
Issue description: Every class I export with “class_name” gives me the specified error when I attempt to reference them in other scripts.
extends Node2D
class_name Space
var row:int
var col:int
var piece:Piece setget SetPiece
func SetPiece(piece:Piece):
self.piece = piece
add_child(piece)
piece.position = Vector2(0, 0)
piece.space = self
func _ready():
pass
EDIT: I did some testing and it looks like that class_name breaks when you have references to two different exported classes in your code. In other words, you can only have one exported class in your whole project.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 21 (6 by maintainers)
It’s been 20 months and you didn’t. Great job. Also, I’m getting this message without any cyclic dependencies, just two classes extending same parent.
UPD: Solved by restarting an editor. Bravo.
I’m having this same issue too, can’t use class_names in the way they’re meant to, lol
@akien-mga I know, I know. And I could go without being misled. I can’t help but picture an “American Chopper” meme in my head: —You have an error! — I don’t! — You have an error! — I checked twice, there’s no error!
And then I google this.
P.S. I’m not passive aggressive. I’m just trying to stay polite while being aggressive due to frustration.
This is still a valid issue I believe. I have two scripts and can only reference one in a script, if I try to reference both, this error comes up.
The problem is the way GDScript is wired: it needs the file fully compiled in order to use it in other scripts. And to fully compile the script, it needs first to fully compile the dependencies. So if any dependency also depend on the current script (that is not yet fully compiled), it won’t be able to resolve the types.
This was always a problem. It’s just exacerbated now with typing because there are many more ways to create cycles.
Note that other languages have similar issues. C++ solves this by using definitions in headers (and even with that it can create unresolvable cycles).
In order to fix this we need to change how GDScript works, and it’s not the time to do it now.
I’ve noticed if I attempt to use a custom class as a type, I need to restart the editor for the error to go away. Especially if I’m using that class as part of defining a type for a given argument in the init of another class.
The error says there’s an error or a cyclic dependency (I actually need to change this error, because not only inheritance can cause this). I need a sample project with a complete reproduction to see if this is not an issue in the code, because the sample code is not complete (I don’t know what
Piece
is).It’s very easy to make cycles when using
class_name
as types, and withis
andas
too.This is looks like a duplicate of #21461. And it’s not really a bug, just that GDScript wasn’t designed to handle circular references, since it never had class names and static typing until now.
@vnen In the mean time, what do you recommend we do to have two-way references? Because this is a very common requirement, like in my case where a board game space and a game piece need references to each other.
In the meantime I will just be using C#, which doesn’t have such issues.
@vnen BeardHeroes.zip