The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I have some scripts that read and modify member variables of a script globally registered with class_name. However, they call the class directly via name, without ever instantiating it (eg. ClassName.variable = 1 instead of var class =; class.variable = 1)
These modifications persist across scenes, so I'd like to know; what exactly is happening to this class under the hood? Is it secretly being instantiated each time I call it in script? Or are its parameters just being stored a single time in memory, waiting to be instantiated with the changes?

This question might be unclear without example, so I'll post one similar to what I'm doing in my project. I ask this mainly because I chose to extend the built-in Object class, and I'm wondering if this repeated class calling is inadvertently creating objects and causing memory leaks.

class_name PlayerStats
extends Object

static var health = 10

class_name Player
extends CharacterBody2D

func heal(amount): += amount
Godot version 4.1
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.