The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

I can't find any tutorials about this, I'm looking for something that has the functionality of a "component" in other engines. I'd like to have something that I can quickly import/insert/load/put into any node and make it have health that can be changed externally. How would I go about that?

Godot version 3.4.4
in Engine by (15 points)

3 Answers

+1 vote
Best answer

You can use a custom Resource for this. There is information about this in the docs:
https://docs.godotengine.org/en/stable/tutorials/scripting/resources.html#doc-resources

I have also created a brief example to demonstrate:
http://kidscancode.org/godot_recipes/basics/custom_resources/

by (22,191 points)
selected by
0 votes

Hi, what I've been doing at least in c#.

It's exposing the component of the concrete node type that
will compose the Health component.

What I mean, Health component must have a clear interface of what its parent should be.

I like to distinct the parents as "Entities" and children as "Components".
And also the complex ones, they are both entities and components at the same time.

But only components will define the behaviour of their parents.

And the parents should only be of one clear interface, concrete Node class.

This might be hard to grasp, I'll try to explain it with text

Entity1RigidBody
--Health: It adds health to a Node parent
--Defense: It adds defense to a Node parent
--VulnerabilityArea2D: An area2D that defines the ranges of vulnerability
----Vulnerability: It adds vulnerability to a given list of groups, requests both health and defense nodepaths.
--Attack: It adds attack to a Node parent

//I'm working this implementation
--StateMachine: It adds a state machine to the parent
----RunState
----WalkState
----AttackState
----IdleState

For the state machine, I haven't been able to make it work, so I plan on making a mediator for that part.

For now in your projects, making a state machine direct child and the states direct children of the main entity would be much easier.

by (14 points)
edited by
0 votes

You may find that using Composition is a better approach:

https://www.youtube.com/watch?v=rCu8vQrdDDI

It's how Godot/GDScript is designed to work, although personally I think using it for something simple like health is overkill, you can do whatever you want!

by (468 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 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.