A Godot Plugin to create generic components to your project's logic to make better maintenance
Works only on Godot 4.x versions
The main goal of the Componentable is to create components to some classes to share responsibility between nodes.
With this you can split the logic in many scripts with low code, and you can customize some behaviours for many nodes with same scene
Example of selection of components on Componentable
The componentable flow is the componentable will always be required, so when you create a component will always have a variable with the componentable as value, but componentable can call the component but the component could not exist.
- You can search "Componentable" on Godot Assets Library
- You can download this repo, copy and paste the
addons/componentable
into your project's folder
To start just select a node and in the inspector click on Create Componentable
Then will be create a Component Script for your node, and your node will be ready to have components
In this example, the Component Script created will be PlayerComponent
, because de class_name of the script in this node is Progress.
Node don't need to have a script, componentable can be used with build-in types
Just create a Script with a class_name
and extends PlayerComponent
, then you can place the behaviour you want inside this component.
in the PlayerComponent
we have:
class_name PlayerComponent extends Node
@export var active = true
@export var player: Player
so we can access the player using the player
variable.
So for in our component example Glowing
will make the player glow with:
class_name Glowing extends PlayerComponent
func _ready():
if active: # active is a variable inside PlayerComponent to make some enabling behaviours
create_tween().tween_property(player, "modulate:a", 0, 1)
then you select the Componentable
node you can select the component
This list of components will show all components that is from this node type and node parent types
when selected a component will show up as a node in components node of your Componentable
Here you can see that we have two variables player
that will be automatic assign as the Componentable
Node, and the active
variable, that will disable the behavior in your logic.
You can make more exported variables to create more customization to your component
When you want to get a component from a Componentable
, you can use:
var glowing: Glowing = Component.find(self, "Glowing")
If you want to get a component from a other node, you can use:
var glowing: Glowing = Component.find(player, "Glowing")
Just remember the component can be null
To add a component to a componentable in runtime you can use:
Component.subscribe(node, "ComponentName")
and to remove a component you can use:
Component.unsubscribe(node, "ComponentName")
Component.componentable(node) # will create a Component Script if don't exists to this node, and define this node as a componentable
Component.uncomponentable(node) # will make this node not a Componentable any more
Component.is_componentable(node) # return true if this node is a componentable
Component.has(node, "component") # return true if this componentable have this component
Component.get_all(node) # return all components in this componentable
- Why you created that? Cuz is so boring to create an Item with a custom name in Bukkit, it's more than 4 lines, and I'm lazy
- I Found a BUG! Click here and open an issue
- Can I help with the project? Sure! just send your PR :D
- Can I contact you? Yep, send email to [email protected]