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

Refactor one folder is making a working Node to be detected as cyclic dependency #47867

Open
immccc opened this issue Apr 13, 2021 · 2 comments

Comments

@immccc
Copy link

immccc commented Apr 13, 2021

Godot version:
3.2.3.Stable

OS/device including version:
Windows 10 Home.

Issue description:
I have two nodes to be defined by a plugin. One instances the other internally, but not vice versa in any way (neither directly nor through a chain of classes)

Both nodes compile and behave as expected. But after refactoring the instanced one to the same folder as its consumer, I get (script error or cyclic dependency) error.

Steps to reproduce:
Given the following source tree:

  • Addons
    • plugin_name
      • plugin.gd
      • controller
        • controller.gd
      • cursor
        • cursor.gd

Refactor to:

  • Addons
    • plugin_name
      • plugin.gd
      • controller
        • controller.gd
        • cursor
          • cursor.gd

Expected:
Plugin behaves the same

Actual:
An error (script error or cyclic dependency) is shown where Cursoris instanced.

Minimal reproduction project:

Inside plugin.gd, instantiation to custom types are done like:

enum CustomType {
    CONTROLLER,
    CURSOR
}


const CustomTypes: Array = [
    CustomType.CONTROLLER,
    CustomType.CURSOR
]

const NamesForCustomType: Dictionary = {
    CustomType.CONTROLLER: "Controller",
    CustomType.CURSOR: "Cursor"
}

const ParentTypesPerCustomType: Dictionary = {
    CustomType.CURSOR: "AnimatedSprite",
    CustomType.CONTROLLER: "Node"
 
 const SourceForCustomType: Dictionary = {
    CustomType.CURSOR: Cursor,
    CustomType.CONTROLLER: Controller
}

const IconPerCustomType: Dictionary = {
    CustomType.CURSOR: "res://addons/adventurator/cursor/cursor.png",
    CustomType.CONTROLLER: "res://addons/adventurator/controller/adventure_controller.png"
}

func _add_custom_types():

    for custom_type in CustomTypes:
        add_custom_type(
            NamesForCustomType[custom_type],
            ParentTypesPerCustomType[custom_type],
            SourceForCustomType[custom_type],
            load(IconPerCustomType[custom_type]))
        print_debug("Added custom type ", NamesForCustomType[custom_type])

 

Nothing fancy in cursor.gd:

tool
class_name Cursor
extends AnimatedSprite

#...

But In controller.gd, instantiation is made like:

tool
class_name Controller
extends Node

var cursor: Cursor = Cursor.new() # <--- This is the line where the issue is shown


func _enter_tree() -> void:
    GlobalRepository.add_controller(self)    # Silly autoloaded plugin for some kind of context for dependency injection

func _ready() -> void:
    
    add_child(cursor)

@Calinou
Copy link
Member

Calinou commented Apr 13, 2021

An error (script error or cyclic dependency) is shown where Cursoris instanced.

Is this error still visible after restarting the editor?

@immccc
Copy link
Author

immccc commented Apr 13, 2021

An error (script error or cyclic dependency) is shown where Cursoris instanced.

Is this error still visible after restarting the editor?

Unfortunately yes. This is only solved when I move back cursor folder to its old position, as sibling of "controller" instead of child.

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

2 participants