What is the meaning of "stale data"?

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

On this wiki page about changing scenes, a con of removing a node from the current tree is that “data contained within the scene will become stale if it relies on delta time, input, groups, or other data that is derived from SceneTree access.”

What does “stale” data mean?

:bust_in_silhouette: Reply From: godot_dev_

I think what it means is that because you are removing the child node from the scene tree, the node won’t benefit from things like signal emissions, calls to _process and other features from being part of the scene tree.

For example, suppose you have a child node named myChild and you get a reference to the node and store it in the child1 variable. Suppose myChild tracks time by using delta from its _process function and the time is stored in a member variable named timeEllapsed. Suppose you remove myChild from the scene. Now _process will no longer be called for that node, meaning timeEllapsed will no longer be updated and will only hold the time right before myChild was removed from the scene tree. In other words, timeEllapsed is now stale. You can still access the stale variable via child1.timeEllapsed, but the value of the variable is stale.

Gotcha, makes perfect sense. Thanks!

mariosio | 2023-06-14 01:36