0 votes

I have about 50 lines of code that I want every UI control in my game to have. What I'd LIKE to do is something like this for a given UI control:

"PlayerNameLineEdit.gd":

extends LineEdit, "res://Boilerplate.gd"

But

gdscript doesn't support multiple inheritance. So what I'm currently doing is:

"PlayerNameLineEdit.gd":

extends "res://LineEditBoilerplate.gd"

"LineEditBoilerplate.gd"

extends LineEdit

But I have to duplicate LineEditBoilerplate.gd for each control type.. TextEdit, MenuButton, and change the "extends" line in each. Every time I want to change my boilerplate code, I have to make a change to 10+ nearly identical scripts.

Is there a better way?

in Engine by (21 points)

1 Answer

+3 votes

Maybe You could make that boilerplate.gd a separate class and just preload and new() it in every control so that it works as a member variable. If You need access to object of control, You can pass it in some setup method for boilerplate class and work with the object similar way as if it was straight inheritance.

by (239 points)
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 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 webmaster@godotengine.org with your username.