- Edited
Hello! I'm dealing with a very weird error after I started using custom classes.
I get this error in one of the instances' script when I try to run the project:
Parser Error: Could not resolve class "BaseEditor". #<-This is my parent custom class
script_name.gd:0 - at function:
If I restart Godot, there will be a message that said instance is corrupt. I ended up deleting a few scenes but it turns out none of them were corrupt.
The actual problem is related to this piece of code from my BaseEditor custom class:
extends PanelContainer
class_name BaseEditor
enum TYPE_EDITOR {
Regular,
Conditioner,
Collector,
Variable
}
func instantiate_editor(type_editor:int):
var editor: PackedScene
match type_editor:
TYPE_EDITOR.Regular:
editor = Console.editor
TYPE_EDITOR.Conditioner:
editor = Console.condition_editor
_:
pass
Console is a Singleton that holds the requested PackedScenes. And it's actually where the error can be fixed:
extends Node
@onready var editor: PackedScene = preload("res://addons/Editor/editor.tscn")
@onready var condition_editor = preload("res://addons/Editor/condition_editor.tscn")
#var condition_editor
In the code above, the first line "@onready" works perfectly. However, if I leave the second @onready as it is, I will get the error Parser Error: Could not resolve class "BaseEditor" at the instance's condition_editor.tscn's script at line 0: extends BaseEditor.
I also get this output in the console:
scene/gui/code_edit.cpp:1709 - Index p_line = -1 is out of bounds (get_line_count() = 21).
scene/gui/text_edit.cpp:5857 - Index p_line = -1 is out of bounds (text.size() = 21).
scene/gui/text_edit.cpp:5851 - Index p_line = -1 is out of bounds (text.size() = 21).
--- Debugging process stopped ---
BUT if I change the second @onready for the line below commented with #, the project works fine. Of course I don't get the PackedScene that I want, but at least the project doesn't stop with an error. No warning about corrupt files either.
It also works fine if I do:
...
TYPE_EDITOR.Conditioner:
editor = load("res://addons//Editor/condition_editor.tscn")
instead of:
TYPE_EDITOR.Conditioner:
editor = Console.condition_editor
So the issue seems to be related with preloading some inherited scenes (not all). Is this a bug? Or there is a mistake since it's my first time using enums, custom_classes and inherited scenes?