Failure to instantiate scene despite it being preloaded

Godot Version

4.x (latest)

Question

I’m trying to instance a start button into my game that emits the signal to instance everything else to begin the gam (I’m currently in a demo state, I’m just including the button so I can section off when certain things happen)

All the button currently does is print("game start!") when pressed. For some reason though, its unable to call a function from my scene that’s in charge of instancing everything else. It says its “failed to instantiate scene of “”, node count is 0” despite me making a reference to a scene with exactly 1 node in it.

code in the button:

const TABLE = preload("res://table.tscn")

# other stuff that isn't important between these two things

func _on_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
	var table = TABLE.instantiate()
	if hovered == true and event.is_pressed():
		print("game start!")
		table._on_game_start()

And the code in the scene swapper:

const STARTBUTTON = preload("res://start_button.tscn")
signal game_start

func _ready():
	var deck = DECK.instantiate()
	var start_but = STARTBUTTON.instantiate()
	add_child(start_but)
	add_child(deck)
	game_start.connect(_on_game_start)

func _on_game_start():
	print("game start received!!")

Am I misunderstanding what preloading and instantiating is? I’d appreciate any help!

You are instantiating table.tscn but you are not adding it to the scene with add_child(). If table.tscn has an attached script and you need its _ready, physics_process, or process functions to run, that will not work.

I see. Won’t that cause issues if table is adding start button as a child and start button is adding table as a child?
If there’s another method to call the script in the table from the start button, with the start button as the child, I’d appreciate if you could share it, or maybe a work around solution?

Ahh, are you trying to use

to get a reference to the table, not as a new table? You don’t have to instatiate a scene that already exists, you can just include a reference to it.

Replace the const in your start button code with:

var table 

and, assuming that your table is the dock, you can simply add this into your scene swapper ready function

start_but.table = deck

Alright so from what I understand.
You’ve replaced instantiating the table (which doesn’t need to happen because its already in the scene) with…I’m not exactly sure.
I’m pretty new to programming so you may need to explain what a “dock” is in reference to the table. I more meant for the table to be a scene swapper.

The game I’m making doesn’t necessarily swap “levels” as much as it does just “clear the board” for a new encounter. So I should be able to use the table for that right? That’s why I was hoping to be able to emit a signal for the table to do something from the start button. How would I do that over using an additional scene for swapping?

Haha, I meant the table is the deck, not the dock. That’s a typo on my part.

Can you clarify a bit more about what you want to do? What exactly is the table scene?

I’m using the table as the thing that instances all the other important scenes. The deck, the player characters, etc. When the start button is saying to start the game, its relaying that signal to the table. The table then tells the deck to draw the cards…wait I’m just realising as I’m typing this that that’s incredibly stupid.

How would I relay signals between siblings that aren’t in the same scene to begin? That’s a significantly more useful piece of info right now

A child emit the signal, the parent listens and gives the order to another child.

Or, parent connect the children signals

One of your preloads is failing.
The key is in the error message:
failed to instantiate scene of “”
scene of “” ie scene of empty string.
I would guess the problem is with:
const STARTBUTTON = preload("res://start_button.tscn")
Is your start button a scene unto itself? Thats not very common. It is more likely your button is an element of a scene.
Can you show your scene tree please?