Rules
Rules are local boolean values on a SparkEntity. They represent simple true/false states like "is dead", "can move", "is grounded", "is in combat", and so on.
What Rules Are For
Each SparkEntity can have a set of rules attached to it through the RulesEntity component. These rules act as flags that other systems and scripts read to determine what the entity is currently allowed to do or what state it is in.
For example:
A "DEAD" rule set to
truemeans the entity is dead. The UI system checks this and blocks opening panels while dead.A "CAN_MOVE" rule set to
falseprevents the character from moving (used during stuns, knockdowns, or ability casts).A "GROUNDED" rule tracks whether the character is on the ground.
Rule Entries
In the Spark Editor under the Rules tab, each RuleEntry defines a rule with:
key
A unique string identifier (e.g., "DEAD", "CAN_MOVE", "GROUNDED")
defaultValue
The starting value when no modifications are active (true or false)
How Rules Work at Runtime
Rules are set by scripts at runtime. When something happens in the game (a character dies, gets stunned, lands on the ground), the responsible system sets the appropriate rule value on the entity.
Other systems then check these rules to decide what to do. For example, the character controller checks the "CAN_MOVE" rule before allowing movement. The UI checks the "DEAD" rule before opening a panel.
Rule Modifications
Rules support temporary modifications with priorities. Multiple systems can modify the same rule at the same time, and the highest-priority modification wins.
For example, a stun ability might set "CAN_MOVE" to false with a duration of 3 seconds and a priority of 10. When the duration expires, the modification is automatically removed and the rule returns to its previous value.
This prevents conflicts where one system sets a rule to false and another sets it back to true at the wrong time. The priority system ensures a clean resolution.
Rule Subscriptions
Systems can subscribe to rule changes and get notified when a rule value changes on a specific entity. This is how UI elements and other reactive systems stay in sync with entity state.
Last updated
Was this helpful?
