0 votes

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

https://i.imgur.com/yeuGK72.png

In the Jogo node, I have this script:

https://i.imgur.com/wiG8byN.png

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

https://i.imgur.com/0Ju5AgK.png

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 (GameManager.gd)'. 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?

in Engine by (90 points)

1 Answer

+1 vote

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.

by (7,934 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.