Godot Version
4.6.1.stable
Question
Why is the reference to a ‘class_name’ class not suitable for a constant expression, but an inline ‘class’ is?
I have a ThemeManager that manages custom Themes.
When I add a newly made Theme for the ThemeManager to manage, I want to only have to add it in one place to prevent the amount of mistakes that are possible (single point of entry).
I have created two themes that both extend an @abstract base class.
# ThemeDefaultDark.gd
extends BareTheme
class_name ThemeDefaultDark
# ...
and in ThemeManager.gd I have added an inline class.
#ThemeManager.gd
# ...
class ThemeDefaultLight:
extends BareTheme
# ...
The amount or types of themes I have does not change at runtime therefore I have created a constant array as the single point of entry to reference them in.
#ThemeManager.gd
const THEMES : Array = [
ThemeDefaultLight, # No problems with inline class
ThemeDefaultDark, # Assigned value for constant "THEMES" isn't a constant expression.
preload("res://ThemeDefaultDark.gd"), # No problems with preload
]
Why does this behave differently?