Replies: 1 comment 2 replies
-
I believe you want something similar to what #361 proposes. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I was wondering if there could be a way to improve the scene composition to be able to make scenes have extra behaviors and/or attributes by just dropping nodes on the scene.
For example, lets say we have many scenes that need to have a
health
attribute and atake_damage
method. And i dont want to repeat the same code everywhere when i need that.So, what i tried so far?
Adding a node to the scene with those things
So lets say i add a
Health
node that has thehealth
attribute and thetake_damage
method. This works, but makes me do something like:While with having the attributes in the script itself was only:
Ok, is just a line, but if you have to do this in a lot of places, it kind of annoys you. Moreover, if i instance this scene in another scene and want to change the health, i have to make children editable, which has other downsides.
Another problem is that you must force nobody in the team use
Health
as a node name for other thing.Inheriting from a base class that has those things
This works and ive used it a lot. But if you need an Area to have this, then a StaticBody, then a KinematicBody, and so on, you will end up repeating code, as extending a node that is inherited by all of this is not advisable.
Node + Autoload
What ive also done is to have a scene
Health
and an autoloadHealthSystem
. So when i need to do damage i do:And the HealthSystem is in charge of doing the checks. I still cannot customize the
health
from the scene tree when i instance a scene.Resources
I can export a var to hold a resource for this, and mark it as local to scene. However i need that export in every script that needs it, and mark them as local for everything too.
Do Traits solve this?
This will be greatly aliviated when gdscript includes traits, as i could simply do
use HealthTrait
in the script. However this will only be for compile time (like 90% of my uses cases anyways).What i would like
I would like to be able to throw a node into a scene, and its methods and attributes be exposed directly in the Owner of the scene. For example Qt Quick works with a similar tree based approach, and has a button that expose certain things as aliases in the root node. However Qt Quick does it by modifying the script and this is not advisable imho for godot.
But it would be nice if, similar to the unique name feature, i could "Mark this node as attribute", and the exported attributes of that node get exposed as if they belong to the owner of the scene. Moreover, i would like that if i select an instanced scene that has this kind of "attribute nodes", i could see the attributes in the inspector. Like a subresource. Something similar with methods.
Or perhaps a keyword as we have for
@tool
, for example, if you use@attribute
in a script the exported variables, and the methods get exposed in the owner of the scene where a node with this script is.This way i could just drop a node to add functionality in a seamless and trasnparent way. Just throwing nodes to the tree, as we always do in godot. No need to modify scripts or whatsoever.
I didnt make this a proposal because im not sure if this makes sense for how is godot built now, but i believe the workflow would be more "godot" than the other approaches i used
Beta Was this translation helpful? Give feedback.
All reactions