GDScript: Overriding static funcs in descendent classes does not work - feature or bug?

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

This does not work as expected. Prints “I am ClassA”. Is there a way to override static methods in descendent classes?

extends Reference
class_name ClassA

static func who_am_i():
	print("I am ClassA");

static func print_who_i_am():

extends ClassA
class_name ClassB

static func who_am_i():
	print("I am ClassB");

extends Node2D
func _ready():
	var class_b = load("res://");

What about You call ClassB.who_am_i() ?
class scripts shouldn’t be loaded, they should be called straight by their classname from anywhere in the script.
Also make sure You manually save both of these scripts before testing.Running project does not automatically save scripts

Inces | 2022-03-21 16:05

Class scripts can totally be loaded, it’s allowed.

Also where did you see running projects doesn’t save scripts? It does by default, although there might be corner cases if the scripts are not referenced by any open scenes (maybe open/find an issue on Github if this is unexpected?)

About static functions:
make sure you understand what you are doing. Did you add static because you really want a static function knowing what it is, or just because you saw an error and put static to “make it go away”?

About the actual problem of class inheritance:
I’m not sure wether this is intented or not. I can’t seem to find an existing issue about this, so you might want to open an issue on Github about the problem you found.

Zylann | 2022-03-23 14:00

scripts not being saved on project run happened to me a lot. It didn’t concern scripts attached to a nodes, but it happened to class scripts, or scripts loaded dynamically at runtime. I could tell, because after quitting project, script in the editor was still marked by *, which means unsaved.

Inces | 2022-03-23 14:26