Bevy Gameplay Tag
A powerful and flexible hierarchical gameplay tag system for the Bevy game engine, inspired by Unreal Engine's Gameplay Tag system.
Features
- Hierarchical Tag System: Create parent-child tag relationships (e.g.,
Ability.Skill.Fire) - Flexible Matching: Support for both exact and hierarchical tag matching
- Reference Counting: Track tag counts with automatic event notifications
- Complex Queries: Build sophisticated tag queries with boolean logic
- Event-Driven: Observer pattern for responding to tag changes
- JSON Configuration: Define your tag hierarchy in external JSON files
- High Performance: Optimized with string interning and binary search
- Type Safe: Leverages Rust's type system for compile-time safety
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
= "0.18"
Quick Start
1. Add the Plugin
use *;
use GameplayTagsPlugin;
2. Define Your Tags (JSON)
Create a tag_data.json file:
Load it in your app:
use ;
new
.add_plugins
.run;
3. Use Tags in Your Game
use *;
use *;
Core Concepts
GameplayTag
The fundamental building block representing a single tag:
let tag = new;
// Exact matching
tag.matches_tag_exact;
// Hierarchical matching (Fire matches Ability.Skill)
tag.matches_tag;
GameplayTagContainer
A collection of tags with query capabilities:
let mut container = new;
// Add tags
container.add_tag;
container.add_tag;
// Query tags
container.has_tag; // Check for tag or parent
container.has_tag_exact; // Exact match only
container.has_any; // Any intersection
container.has_all; // All tags present
GameplayTagCountContainer
Reference-counted tags with event notifications:
let mut tag_container = new;
// Increment tag count
tag_container.update_tag_count;
// Decrement tag count
tag_container.update_tag_count;
// Set absolute count
tag_container.set_tag_count;
// Get current count
let count = tag_container.get_tag_count;
Tag Change Events
React to tag changes using Bevy's observer pattern:
Complex Queries
Build sophisticated tag queries with boolean logic:
// Create a query expression
let mut expr = new;
expr.all_tags_match
.add_tag;
expr.no_tags_match
.add_tag;
let query = new;
// Test against a container
if query.matches
Tag Requirements
Define declarative tag requirements:
let mut requirements = new;
// Must have these tags
requirements.require_tags.add_tag;
// Must NOT have these tags
requirements.ignore_tags.add_tag;
// Check if requirements are met
if requirements.requirements_met
Use Cases
Skill System
// Define skill tags
let fire_skill = new;
let cooldown = new;
// Cast skill
tag_container.update_tag_count;
tag_container.update_tag_count;
// Check if skill is on cooldown
if tag_container.has_matching_gameplay_tag
Buff/Debuff System
// Stack buffs with reference counting
let strength_buff = new;
// Add 3 stacks
tag_container.update_tag_count;
// Get stack count
let stacks = tag_container.get_tag_count;
println!;
State Machine
// Define states as tags
let idle = new;
let running = new;
let jumping = new;
// Transition states
tag_container.set_tag_count;
tag_container.set_tag_count;
Team/Faction System
let player_team = new;
let monster_team = new;
// Check if entities are on the same team
if entity1_tags.has_any
Performance
- String Interning: Uses
string_cachefor efficient string storage and comparison - Binary Search: O(log n) tag lookups in sorted containers
- Lazy Updates: Parent tags are updated only when necessary
- Efficient Counting: HashMap-based reference counting
Examples
Check out the examples directory for complete working examples:
Architecture
src/
├── lib.rs # Module exports
├── gameplay_tag.rs # Core tag definition
├── gameplay_tags_manager.rs # Tag manager
├── gameplay_tag_container.rs # Tag container and query system
├── gameplay_tag_count_container.rs # Reference-counted tag container
├── gameplay_tag_requirements.rs # Tag requirements system
└── gameplay_tags_plugin.rs # Bevy plugin integration
Compatibility
| Bevy Version | Plugin Version |
|---|---|
| 0.18 | 0.1.0 |
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Acknowledgments
This project is inspired by Unreal Engine's Gameplay Tag system, adapted for the Rust and Bevy ecosystem.