Setget in subclass

Godot Version



There is a class for Character

class_name Character
extends Resource
@export var hp:float 
@export var hp_max:float
@export var atk:float
@export var def:float

after that , I made a new subclass

class_name PlayerDM
extends Character

@export var hp_max: float = 100.0: 
		return hp_max
		hp_max = value
		UI_EVENT.hp_info_changed.emit(hp, hp_max)
@export var hp: float = 100.0 :
		return hp
		hp = value
		UI_EVENT.hp_info_changed.emit(hp, hp_max)

I know there are some error in this code, redefine I mean.
But what Can I do for override the subclass’s set and get ?

I believe the function would be set_hp_max(x) and get_hp_max(x) in the subclass, but you would have to define the set/get in the parent class first

1 Like

Try using the alternative syntax for getters and setters

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.