I’ve created a generic class that is a super class to create a lot of Inherited Scenes from it. In this class I have some @export to change the values on Inherited Scenes but whenever I do change this values does not works on Inherited at inspector and only works values from the Super Class. If I change the values on function _ready it works well, but not on the Inspector.
How could I fix it ?
Super Class
#super class
class_name CharacterBase extends CharacterBody2D
#enums
enum CharacterType { PLAYER, ENEMY }
#EXPORT
@export_category("Char Conf")
@export var char_type:CharacterType
@export var speed: float = 50
@export var attack_damage:int = 1
@export_category("Health Conf")
@export var life_health:int = 50
@export var middle_health:int = 25
@export var min_health:int = 10
Inherited Scenes
#inherited scene Player
class_name Player extends CharacterBase
#it works but changing the value of speed on the inspector does not
func _ready() -> void:
speed = 150
#inherited scene Enemy
class_name Caius extends CharacterBase
#it works but changing the value of speed on the inspector does not
func _ready() -> void:
speed = 50
Are you changing the values in the inspector on the super class, or the sub class? This is because changing the value on the sub class unlinks it from the values in the super class, so changing the value in the super class after that will not affect the value in the sub class.
It’s not an answer to your question, but I would recommend to immediately ditch this inherited scene approach. I tried something similar to what you’re doing in Godot 4.1 or 4.2, and eventually the whole thing completely fell apart. Values don’t update, when you want to change something more fundamental in the base class the whole project breaks, you cannot load the scenes anymore, you have to manually go and fix some scene files etc.
I don’t doubt it works if you know how to use it, but the feature from a user’s point of view is completely broken. The editor has no safeguards and doesn’t even know itself how this feature works. Don’t do it.
Hey! I’ve run into the same thing before in Godot 4 — it seems to be a quirk with how exported variables in inherited scenes are handled. When you inherit a scene, the values from the parent script don’t always become editable in the child scene’s inspector unless you make the variable explicitly editable again in the inherited script.
To fix it, try re-exporting the variables in the child scene’s script even if you’re not changing the logic. For example:
gdscript
Copy
Edit
Player.gd (inherited scene)
@export var speed: float = 150
That should make the value show and save properly in the inspector for the inherited scene.