|
|
|
|
Reply From: |
lukas |
get_tree().quit()
More info in handling quit request tutorial.
How about restarting the scene? I know it’s not practical for game, but for debugging it makes some things faster.
Jukepoks1 | 2016-12-30 15:40
@Jukepoks1 Easiest way is to change scene to current scene:
get_tree().change_scene("res://current_scene.tscn")
The current scene will be freed and then loaded again.
Thanks for fast answer!
I figured this would work little better, so the filename is not actually hard-coded:
var currentScene = get_tree().get_current_scene().get_filename()
print(currentScene) # for Debug
get_tree().change_scene(currentScene)
Jukepoks1 | 2016-12-30 16:18
Thanks. I edited the link in the answer.
Im using get_tree().quit()
too to close the game in-game but it is giving errors on my console(not the outputbox, literal non-gui console). heres the error
OpenGL ES 3.0 Renderer: GeForce MX130/PCIe/SSE2
ERROR: ~List: Condition ' _first != __null ' is true.
At: ./core/self_list.h:111
ERROR: ~List
I want to exit my game error free so what do I do?
Regarding the last question:
I’m not quite sure I fully grasp the relationship of classes to nodes yet.
But as I understand, this error comes up when there are class instances initiated with the new() method that don’t get cleaned up at the end.
E.g. in a script Chest.gd
, that is attached to a node:
const Potion = preload("res://Potion.gd")
var my_potion
func _ready():
my_potion = Potion.new()
It looks like instances that aren’t attached to a node, like my_potion
, won’t get cleaned up automatically.
You need to do it manually like so:
func _exit_tree():
my_potion.free()
_exit_tree
will automatically be called on quit, if the script that contains it is attached to a node, like Chest.gd
in this example.
It will, however, not be called, if you put it into Potion.gd
itself, because that script has never been in the tree in the first place, as it wasn’t attached to a node.
James Sauer | 2020-04-12 00:57