0 votes

Overview

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

Issue

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.

Example

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!

Godot version 3.4
in Engine by (20 points)

1 Answer

0 votes
Best answer

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
by (6,876 points)
selected by

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.