Skip to content

Beehave Singleton Registration possibly break plugins like Phantom Camera #442

Description

@RawsharkTang

Godot version: 4.7.1
OS: windows 11

Describe the bug
When using Phantom Camera alongside the Beehave plugin, Godot throws the error: Failed to retrieve non-existent singleton 'PhantomCameraManager' and other scripts are reporting null reference.

The PhantomCameraManager Node is a tool script that is referenced in the editor scene tree,and the scene camera nodes will locate the manager node from _enter_tree.

It could be related to the latest Godot 4.7.1 autoload guard fix.
The Beehave is working fine but is somehow causing the Godot Editor to kill the PhantomCameraManager (the registerd node is lost)
This is the manager node and it would register itself when entering tree.

@tool
extends Node

func _enter_tree() -> void:
	if not Engine.has_singleton(_CONSTANTS.PCAM_MANAGER_NODE_NAME):
		Engine.register_singleton(_CONSTANTS.PCAM_MANAGER_NODE_NAME, self)
	Engine.physics_jitter_fix = 0


func _exit_tree() -> void:
	if Engine.has_singleton(_CONSTANTS.PCAM_MANAGER_NODE_NAME):
		Engine.unregister_singleton(_CONSTANTS.PCAM_MANAGER_NODE_NAME)

To Reproduce
Steps to reproduce the behavior:

  1. Install both plugins and enable phantom camera first, then enable beehave
  2. restart the editor

Investigation
I ran several tests and tried to find the cause. It's possibly a conflict in the Godot plugin lifecycle initialization between the two plugins.

  1. Blang Plugin Test: Created an empty plugin to test Godot's register_singleton / add_autoload_singleton API works ok.

  2. Single Plugin Test: Phantom Camera alone does not produce the error. The bug only manifests when the Beehave plugin is also enabled.

  3. Possible Lifecycle Conflict: I found that Beehave is registering its singletons inside the _init() method:

    func _init():
        name = "BeehavePlugin"
        add_autoload_singleton("BeehaveGlobalMetrics", "metrics/beehave_global_metrics.gd")
        add_autoload_singleton("BeehaveGlobalDebugger", "debug/global_debugger.gd")
        
        # Add project settings...
  4. **Workaround Fix:**I modified Beehave's code by moving the singleton registration to _enable_plugin(). This does fix the issue on phantom camera plugin.

    func _enable_plugin() -> void:
        add_autoload_singleton(METRIC_NAME, "metrics/beehave_global_metrics.gd")
        add_autoload_singleton(DEBUGGER_NAME, "debug/global_debugger.gd")
  5. I also commented out the utils/utils.gd method that searches for the plugin, replacing it with EditorInterface singleton

    var border_size := Vector2(4, 4) * EditorInterface.get_editor_scale()
    var editor_main_screen = EditorInterface.get_editor_main_screen()

Additional context
Im not sure if i should report this issue here, since it feels like a godot problem, but just in case others also encountered it and needed the workaround

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions