Cannot convert from Object to Object?!

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Fupicat

I have a scene called Jogo that has the main menu:

In the Jogo node, I have this script:

And in the Menu Principal (main menu) node, I have this script:

The function receives the “button pressed” signal from the play button and checks if the Jogo node exists. If it doesn’t, it displays an error message. If it does, it calls the “carregar_cena” function in the Jogo node.

But for some reason, when I do that, I get the following error:

Invalid type in function 'add_child' in base 'Node ('. Cannot convert argument 1 from Object to Object.

What does Godot mean by “Cannot convert argument 1 from Object to Object”? What am I doing wrong?

:bust_in_silhouette: Reply From: eons

That error message sounds like a typo (bug), but I see some problems there.

Use queue_free to free on nodes in the tree, and if I understand your code right, you are trying to add_child with a PackedScene, you need to call load_cena.instance() to get an instance of your scene, then add it to the tree.