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?

  • xyz replied to this.

    xyz But Console doesn't reference BaseEditor as far as I know. It's just holding the preloaded PackedScenes so every Editor can get them.

    The problem even persists if I preload that specific scene inside BaseEditor without using Console. It doesn't happen if I use load() instead of preload().

    • xyz replied to this.

      xyz Yes, I was able to reproduce it in small scale: https://www.dropbox.com/scl/fo/5rev76nhfixf8j47ckyus/h?rlkey=40s1i48mmguq5dayxo201cvj7&dl=0

      (Sorry, I still don't know how to use github).

      I'm pretty sure it has to do with what you mentioned about circular dependency. I found some known issues that seem pretty similar:

      https://github.com/godotengine/godot/issues/80877
      https://github.com/godotengine/godot/issues/77090
      https://github.com/godotengine/godot/issues/76641
      https://github.com/godotengine/godot/issues/64330

      It feels like my instanced scene file is corrupted even though it has the same content than other working instances. Now I'm afraid to create another instance and work with that because it may get corrupted. I left some comments in my main file in case you check it out!

      • xyz replied to this.

        Godoten Godot says editor_condition.tscn is invalid/corrupt.

          xyz It seems it gets "corrupted" when you close and reopen the project after the error is presented.

          The "corruption" has something to do with those errors, which seem like bugs:

          scene/resources/packed_scene.cpp:92 - Condition "nc == 0" is true. Returning: nullptr
          editor/editor_data.cpp:880 - Index p_idx = 1 is out of bounds (edited_scene.size() = 1).

          I noticed that when you Edit dependencies it says "Resource 'editor_condition.tscn' is in use", even though it can't open.

          Anyways, you can reproduce the error yourself with a new scene:

          1. Create a new Inherited scene from Base_editor.
          2. Change the root node's name to anything you want and save it.
          3. Detach the script from the root node and create a new one.
          4. Make the script extend BaseEditor.

          If you run that scene at this point it will work fine. If there is an error it's because of a wrong path at Global.gd.

          The real problem starts the moment you go to Global.gd and preload() the new scene you just created at @onready var editor_condition. It will show the following error when you try to run the project or the scene:

          Parser Error: Could not resolve class "BaseEditor".

          Load works fine. Preload doesn't. I get it's related to circular dependency. I just don't get what part of it is circular and why it doesn't happen with editor.tscn which also inherits from BaseEditor and is using preload just fine.

          BTW: if you close the editor with preload active in Global.gd, the file will be "corrupted" the next time you open it, even though the file itself seems fine.

          • xyz replied to this.

            Godoten Whatever it is, you should redesign the system so it doesn't have any circular dependencies. Base classes have no business referring to inherited classes in any way.

            The file was corrupt immediately upon opening. There's also a bunch of tmp files and a lot of stuff in .godot. This looks like a stripped down project, not a minimal reproduction. Try to reproduce it in a fresh project with less nodes and less code.

              xyz

              Base classes have no business referring to inherited classes in any way.

              Oh, so the circular dependency in this case is BaseClass instantiating its derived scenes, that's why the error happens even when I don't use Global.gd? Alright, good to know. I will study more about this, maybe read a book about desing patterns. Thank you!