Cables
by jospete
godot-addon-cables
A Godot plugin to serve as an alternative to Autoload Event Buses
for a more visual / editor gameplay design approach.
The implementation of this addon is very much inspired by Ryan Hipple's 2017 Talk
on using Unity ScriptableObject
s as an alternative to singletons.
Usage
The general flow for usage is:
- Right-click on any folder in the
FileSystem
tab >Create New
>Resource...
- Search for
Cable
> clickCreate
- Name your Cable something useful like
player_death_event.tres
orplayer_health_value.tres
- Produce values on the cable - this can be done by either producing a value on a
Cable
directly vianotify()
(e.g. for primitive values likefloat
,string
,int
,bool
etc), or using aCableValueProducer
node to emit events / data on the cable. (NOTE: the producer should generally be a child of the node that is producing the value) - Consume values from the cable - this can be done by adding the
CableValueConsumer
node as a child of the node that wishes to consume value updates
Available Producer Types:
CableNodeValueProducer
- sendsNode
references across theCable
, and automatically clears the reference when the producer gets destroyedCableButtonEventProduer
- translates a button click into aCable
event; useful for quickly wiring up UI across scenesCableInputEventProducer
- translates input actions intoCable
events; this is more niche, but can help cover some edge cases for prototyping
See the examples
folder for more granular implementation details
Best Practices
It is best to use Cable
resources for global state, such has passing data to UI components (e.g. player health ratio to a healthbar widget) or sharing atomic data like enemy count, number of coins, or even a shared node reference to a manager script that holds these.
You should not use Cable
resources when transferring local state, such as watching a single monster's CollisionShape2D.area_entered
event to apply damage to the monster (e.g., multiple instances of the monster scene will all broadcast on the same assigned Cable
resource).
Download
Support
If you need help or have questions about this plugin, please contact the author.
Contact Author