Setget Inheritance?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Clifford


I have a base scene for creating enemies
This base scene has a set get for turning the process, collision (and other things all enemies share in common) on and off

Using the base I created enemies
Each enemy has different extra things from the base that need to be turned on and off


I found out that only the children setget function is called, the parent is never called.

This also happens with signals, when a base parent have a signal connected to a function with base logic that is common to all the children, the children cannot add extra behavior to it.


in base

var is_active: bool = true setget set_is_active

func set_is_active() -> void:
# do something

in a child

func set_is_active() -> void:
# do extra things

somewhere else

child.is_active = false

this will only run the child do extra things, not the base do something

I think I am doing this wrongly, could anyone advice me on this please?
For now I repeated the common logic within different enemies but would love to be able to have it just in the parent…
Thank you in advanced!

:bust_in_silhouette: Reply From: Wakatta

No your way is correct and it works as intended.
If you also want the base class’s operations then supersede using when you want it to happen

in a child

func set_is_active() -> void:
.set_is_active() # call base class implementation
# do extra things

child.is_active = false

Thank you! I did not know you can call the base class like that.

Clifford | 2021-12-04 04:42