Overview
WCGASAbilityGrantRegistry is a World Subsystem that serves as the centralized tracking system for all abilities granted to Ability System Components (ASCs) across all granting systems in the Wonderscape GAS Ally plugin. It automatically initializes per-world, tracks which systems have granted which abilities to which ASCs, prevents duplicate ability grants, and ensures safe removal by verifying no other system still requires the ability before allowing it to be cleared from the ASC.
Purpose
The Ability Grant Registry orchestrates ability grant coordination and removal safety by providing:
- Duplicate Prevention: Prevents the same ability from being granted multiple times to an ASC when multiple systems (Feats, Curriculum, Skill Trees, etc.) request it
- Multi-Source Tracking: Records every system that has "ownership" of each ability grant with Source type and SourceID tag identifiers
- Safe Removal Guarantees: Only allows ability removal when the requesting source is the last remaining owner
- Automatic Cleanup: Uses weak references to ASCs and periodic timer-based cleanup to automatically remove stale entries when ASCs are destroyed
- Handle Storage: Stores the
FGameplayAbilitySpecHandle from the first grant so subsequent systems can reference the same ability instance
- Event Broadcasting: Notifies game systems via delegates when abilities are first granted, finally removed, or when duplicates are prevented
- Query API: Provides comprehensive lookup functions to check grant status, source ownership, and retrieve abilities by source type
- Debug Support: Offers development-only functions to inspect registry state for troubleshooting
How It Works
Initialization Flow
- Subsystem Startup: When a World initializes (Game, PIE, or GamePreview), the subsystem is created via UE's subsystem lifecycle
- World Type Validation:
ShouldCreateSubsystem() ensures the registry only exists for playable worlds (not editor preview)
- Timer Setup: Starts a 30-second repeating timer calling
CleanupStaleEntries() to remove destroyed ASC references
- Log Initialization: Logs world name to
LogWCGASSubsystems for debugging