Godot Version
4.2
Question
In my game I have resources for the different Goods in the game. I have a parent class called Good. I also have child classes of Good such as Food, Ore, etc.
I want every Good to have a good_name, so in the Good class I have
extends Resource
class_name Good
static var good_name:String = "Default Good Name"
and in the child class I have
extends Good
class_name Food
func _init():
good_name = "Food"
In other parts of the code, I want to get any Good Resource and the name of that resource.
But if the variable is just a resource or reference to the Food Resource then in order for good_name to be “Food” and not “Default Good Name” I need to call good_res.new(), just so that good_res.new().good_name is “Food” and not “Default Good Name”. But do I really have do call .new()? That is not efficient. Is there a way to have a static var for a Resource that is different for different sub classes?