problems with scenes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By flonkopaten
:warning: Old Version Published before Godot 3 was released.

i have a main scene “Spatial.tscn” and in my game when i “die” i want to reload the scene from begining, and i do that with this :
get_tree().change_scene("res://scen/Spatial.tscn")

my character is a cube in a KinematicBody and that character is made on its own scene and i add it to my main scene with the “chain” button.

It works good until i reloaded the scene a few times, my game is getting slower and suddenly it dont detects collisions.
So i wonder if i need to free the old scene?
or what can cause this effect?

get_tree().change_scene(), get_tree().change_scene_to(), and get_tree().reload_current_scene() will all automatically delete the previous scene and load the new one, so that shouldn’t be a problem. There may be other nodes that you aren’t freeing, though. This can happen if you make a node, or load a scene but don’t add it as a child, or if you remove a node from the scene but never free it.
While you’re playing the game open the Debugger, and click on the Monitors tab. Scroll down to “Object” and watch it, if the nodes and objects continue to rise even after reloading the current scene then something isn’t being freed.

CowThing | 2017-01-12 03:06

It seems that there could be not-freed instance.

There are several cases.

  1. Made an instance with code but not add_child()
  2. Just only remove_child() instead of queue_free() or free()

All nodes are freed when change_scene() if all nodes are remained in scene.

volzhs | 2017-01-12 06:14

Look at the remote inspector on the debugger, maybe you are adding nodes as child of the main viewport instead of the scene and remain there when changing scene.

eons | 2017-01-12 12:56

Thanks for the answer and advices, i checked the debugger and the objects and nodes remains the same when i reload the scene so i guess thats not what is causing the problem. I am not so sure that the game actually is getting slower for everytime i reload the scene, and thats not the big problem, the big problem is that i randomly after a few reloads lose the collision detection.
I am not sure then if i made the collision handling correct, though i use a kinematicbody, with the child nodes meshinstance, camera and a area with a child node “collisionshape” i did not find any good tutorial on this so just experimented and found that this worked for my game, and i only detect the collision with the “func _on_Area_body_enter( body ):”
where i decide what will happen when colliding.
Any advice on this would make me happy :slight_smile:

flonkopaten | 2017-01-12 13:42

I now know that the lost of collision detection happens after a few reload of the scene, but always very random sometimes after 1 reload and sometimes after 7 reloads and so on…

And as i said i cant see any more objects or nodes after any reload in the debugger, only thing i notice is the “collision pairs” amount is getting lower when it stops detect collision…

what should i do and what to check?

flonkopaten | 2017-01-12 17:05

i am not sure i understand what you mean with adding nodes as child of main viewport? or what to look for in remote inspector?
I am new to this and try to learn.
I see in remote inspector this:root and my scene and all its nodes. Is that what i should see?

flonkopaten | 2017-01-12 17:20

The scene sounds fine, it should show the root plus any atutoloaded stuff and current scene.


I have similar problem with a game, sometimes the scenes are loaded and in rare cases one of the many areas lose collision but still not sure if is a shape or connection problem, is really rare and not sure how to test it.

eons | 2017-01-12 23:17