Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Rednib |
Hello community,
im pretty new to Godot and playing around with Godot to get used to it. I’m a programmer for about 15 years but i’ve never used an editor like Godot before. I guess i’m thinking to complicated and have to get used to Godot and the way things are made with Godot.
My question is: how can i access a node and it’s methods inside another scene?
I’m playing around with plugins and wanted to add a simple button to the 2D canvas toolbar. That’s working fine. But i wanted to show a window dialog when i click the button. So i created another scene with the window dialog in it. Now i need to call the “popup” method of the window dialog when i click the button.
But somehow it can’t find the method popup().
Here is the code i’ve written so far:
General editor script:
tool
extends EditorPlugin
var button # A class member to hold the button during the plugin lifecycle
func _enter_tree():
button = preload("res://addons/my_custom_button/my_button.tscn").instance()
add_control_to_container( CONTAINER_CANVAS_EDITOR_MENU , button )
func _exit_tree():
remove_control_from_container( CONTAINER_CANVAS_EDITOR_MENU, button ) # Remove the button
button.free() # Erase the control from the memory
enter code here
Code of the button itself:
tool
extends Button
var window
func _enter_tree():
connect("pressed", self, "clicked")
window = preload("res://addons/my_custom_button/WindowDialog.tscn").instance()
func clicked():
print("You clicked me!")
window.popup()
And here the error message:
res://button.gd:12 - Invalid call. Nonexistent function 'popup' in base 'Nil'
It basically says that i don’t have a reference to the window dialog and thats why it can’t find the popup() method.