on startup, I want to get some objects in the scene, for my editor plugin
@tool
extends EditorPlugin
func _enter_tree():
var Scene = EditorInterface.get_edited_scene_root()
print( "scene = " + str(Scene) )
this usually works fine, but if the plugin is already open when Godot is launched, the plugin seems to not yet register the loaded scene. it print “Scene = null” !!
also, if we switch scenes, the plugin needs to register the changed current scene. How do I do this?
how do I get the current scene in editor interface, and update it on scene change or once scene is loaded to make sure we are working with the correct nodes in the correct scene?
I mean, I could do this:
func _process(delta):
var Scene = EditorInterface.get_edited_scene_root()
print( "scene = " + str(Scene) )
but that seems repetitive and unnecessary. surely I could only update the the variable with out scene root on scene change to get the nodes within? only once instead of repetitively??
have you tried this? It kinda seems like you didn’t read what I posted and just rushed to post whatever. Yes I have read those docs and tried to do this but it wont work… am I missing something here?
ok. Please try it on your end to confirm because, as Ive said repeatedly, it does not work for me. are you on Godot version 4.2.1? have you tried this code?
for me, naming scene_changed.connect(_on_scene_change) or scene_changed.connect(scene_changed) or scene_changed.connect(pumpkin_spice_latte) or anything after scene_changed.connect just simply does not work, because the scene_changed method does NOT use connect, hence the error:
Cannot find property “connect” on base “Callable”.
thank you for your effort and I appreciate if you could try it and get back with something that works or an explanation that can shed light on the issue concerning this error.
If you have a scene_changed() method in your script, rename it to anything else.
Full script:
@tool
extends EditorPlugin
func _enter_tree() -> void:
scene_changed.connect(_on_scene_change)
func _exit_tree() -> void:
scene_changed.disconnect(_on_scene_change)
func _on_scene_change(scene:Node) -> void:
print('Changed scene to %s' % (scene.name if scene else "empty"))
Result in the Output dock:
Changed scene to TestArea2DCollision
Changed scene to AudioManager
Changed scene to empty
Changed scene to Test2DGlow
Changed scene to Test2DHDR
Changed scene to TestAnimationPlayerChangeSpeed
Changed scene to empty