Inherited Scene does not respect values of export from parent scene in theirself?

Godot Version

4.3

Question

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

PS: Sorry by my english

Remove the _ready function from child class and then change value from inspector. I did this on my machine and it is working completely fine.

Try this and let me know.

I did your suggestion and it still does not working. By the way, what can I use instead of _ready ? Thanks for your attention

if you have a bulk or some lines of code you have to use _ready function. but if you want to deal with one variable you can use “@onready” notation.

1 Like

I have some functions and signals that I call in _ready because this I can’t to use @onready

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.

1 Like

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. :slight_smile:

1 Like

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.

If I try this throw an exception “The member speed already exists in parent class CharacterBase”

See the image below please

I’m changing the sub class. The sub class is keeping the values from super class and I don’t know how could I fix it

actually you are redefining your variable that already exists in parant class