How do i make data save across the changing of scenes?

its just something ive wanted to learn in godot for a long time, and i think it might be useful in feature projects.

Keep it in autoloads or static properties.

would it be ok if you could explain to me how to use static properties?

Static variables are shared among all instances of a script.

static var max_id: int = 0
var my_id: int

func _ready() -> void:
    my_id = max_id # every new object takes the current max id
    max_id += 1    # then adds one to the max

thank you very much!

Static properties are not dependent on objects (aka class instances). They live inside the namespace of the class they are declared in but are basically global and cannot be destroyed, hence they’ll “survive” scene swapping as they are not tied to any node in the scene tree that may get wiped out when the scene changes.

You can have a dedicated “static class” that holds all of your persistent data in static properties:

class_name Persistent

static var my_data1: int
static var my_data2: float
# etc

Those static vars will be accessible from any other script like this: Persistent.my_data1

thank you normalized! very cool!