'Godot - get_node: Node not Found - GDScript
Please help! I keep getting this error message when I run my code for a title page for my game! I'm quite new to Godot. Here's the scene tree:
TitleScreen - Control Node
- ColorRect - ColorRect Node
- Menu - VBoxContainer Node
- Label - Label Node
- Buttons - VBoxContainer Node
- PlayButton - Button Node
- QuitButton - Button Node
- Fade - ColorRect
Here is the GDScript code connected to both the PlayButton and the QuitButton:
extends Button
export(String) var scene_to_load
export(bool) var quit
func _ready():
for button in $Menu/Buttons.get_children():
button.connect("pressed", self, "_on_button_pressed", [button.scene_to_load])
func _on_button_pressed():
get_tree().change_scene(scene_to_load)
When I run said Scene I get:
get_node: Node not Found: Menu/Buttons
Any Help would be appreciated :)
Thank you for your help with solving my problem! My Title Screen After being fixed :)
My game Game
Solution 1:[1]
You said you've connected the GDScript code to each Button, but it looks like you should have the script connected to the TitleScreen instead as $Menu is a child of TitleScreen and not Button.
You'll need to fix the script also to extend Control instead of extend Button as it is currently
Edit
Honestly though, if you just want to load a particular scene from a button press and nothing else you can simply change the scene directly from the button - this is just a script change
extends Button
export(String) var scene_to_load
export(bool) var quit
func _ready():
self.connect("pressed", self, "_on_button_pressed")
func _on_button_pressed():
get_tree().change_scene(scene_to_load)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
