i get the error “Attempt to call function ‘instantiate’ in base ‘previously freed’ on a null instance” in a scipt where i intend to create and delete scenes for navigating menus.
i use a function in a permanent scene to “transit” between scenes that are children of the permanent scene. I’m trying to implement return buttons in every scene for smoother navigation but that’s where i get the error.
here is all relevant code to this error:
the Startup scene and script are the permanent scene.
This is a very early prototype and i’m probably trying to this in a way that’s so very not optimal so if you have any suggestion on how to do menu navigation easier i’m all for it, please tell me
Whenever you set sceneExited (or any other node) to another node, use Node.duplicate. Otherwise, you will just create a reference to the node and when it is freed, that reference becomes invalid.
One thing I would like to add is that your code is generally more readable if you use static types because it makes it immediately visible which variable has which members and what its function is. I believe this is just preference though and there are people that don’t use it.
youre passing a null instance on parent.sceneExited since the variable wasnt declared in that scope put that variable in your control node that these extend from
The error message means that you are trying to call a method on a node that does not exist anymore. This is probably because, in transitScene, you are setting sceneExited directly to sceneOut and then calling queue_free on sceneOut. So now both sceneExited and sceneOut are ‘previously freed’ and cannot be used anymore. But sceneExited is used in _on_return_pressed
Okay i think i get it: you use the node duplicate to store it’s value into a var because if you don’t and you delete the node right after you assigned a var to it’s value, the var becomes null.