Install Asset
Install via Godot
To maintain one source of truth, Godot Asset Library is just a mirror of the old asset library so you can download directly on Godot via the integrated asset library browser
Quick Information
A simple addon to make UI / Game Logic reactive in Godot 4.x (GDSCript).Inspired by the signal/reactive systems in modern frontend frameworks (like React, Vue, and SolidJS).
ReactiveSignal
A simple addon to make UI / Game Logic reactive in Godot 4.x (GDSCript).
Inspired by the signal/reactive systems in modern frontend frameworks (like React, Vue, and SolidJS).
β¨ Features
- True Reactivity: No need to manually connect or emit signals. Simply access data inside
use_effect, and the dependency tracking is automatically handled. - Lightweight & Efficient: Built on top of
RefCountedfor automatic memory management, preventing memory leaks. - Zero Coupling: Keeps your data layer completely decoupled from the view layer, significantly reducing boilerplate code like
connect()andemit_signal().
π Quick Start
1. Basic Usage (Data Responsiveness)
Use use_effect to track and respond to data changes automatically:
extends Node
func _ready() -> void:
# 1. Create a reactive signal
var score = ReactiveSignal.new(0)
# 2. Define a side effect (automatically runs whenever score.value changes)
ReactiveSignal.use_effect(func():
print("Current Score: ", score.value)
) # Prints: "Current Score: 0"
# 3. Modify the data, which automatically triggers updates
score.value = 10 # Prints: "Current Score: 10"
score.value = 10 # Value unchanged, won't trigger
score.value = 25 # Prints: "Current Score: 25"
2. Auto-Updating UI Components
Perfect for scenarios where multiple UI elements share and display the same state:
extends Control
@onready var label_1: Label = $Label1
@onready var label_2: Label = $Label2
# Create a global or local state
var player_hp = ReactiveSignal.new(100)
func _ready() -> void:
# Keep multiple UI elements in perfect sync automatically
ReactiveSignal.use_effect(func():
label_1.text = "HP: " + str(player_hp.value)
label_2.text = "Health: " + str(player_hp.value) + "%"
)
func _on_damage_taken(amount: int) -> void:
player_hp.value -= amount # UI updates automatically! No need to manually assign Label.text
π οΈ API Reference
ReactiveSignal
Methods
static func use_effect(effect: Callable) -> voidExecutes the provided closure function and automatically collects anyReactiveSignalinstances accessed within it. When thevalueof those instances changes, theeffectis automatically re-invoked.func _init(initial_value) -> voidConstructor that initializes the signal with its starting value.func clear_effects() -> voidManually clears all tracking side effects bound to this signal instance (useful for manual cleanup or destruction).
Properties
var valueGet: Returns the current value. If called within ause_effectclosure, it automatically registers the effect as a dependency. Set: Assigns a new value. If the new value differs from the current one, it dispatches and re-runs all dependent effects. It also automatically cleans up any stale or invalid (freed) Callables during the dispatch process.
π¦ Installation
- Download or clone this repository, and copy the
addons/ReactiveSignalfolder into your Godot project's root directory. - Open the Godot Editor, navigate to Project -> Project Settings -> Plugins.
- Locate ReactiveSignal and check the Enable box.
π License
This project is open-source and licensed under the MIT License. See the LICENSE file for more details.
A simple addon to make UI / Game Logic reactive in Godot 4.x (GDSCript).
Inspired by the signal/reactive systems in modern frontend frameworks (like React, Vue, and SolidJS).
Reviews
Quick Information
A simple addon to make UI / Game Logic reactive in Godot 4.x (GDSCript).Inspired by the signal/reactive systems in modern frontend frameworks (like React, Vue, and SolidJS).