Skip to content

MuharremTozan/Agentic-Duel / .agent/skills/unity-so-prefab-manager

unity-so-prefab-manager

Verified

Manages the structured relationship between ScriptableObjects (Data) and Prefabs (Logic/Visuals) in Unity 6. Follows the 'SO-to-Mono' Bridge pattern to ensure instance independence (e.g., individual health for identical robots) while maintaining a clean, data-driven architecture. Use when: (1) Creating new unit/item types, (2) Wiring SO data to Prefab MonoBehaviours, (3) Resolving data-sharing bugs where changing one SO affects all instances.

references/bridge-pattern.md

View on GitHub
# The SO-to-Mono Bridge Pattern

## Problem: The "Shared Soul" Bug
In Unity, ScriptableObjects are **assets**. If you have two Robots referencing the same `RobotSO` and you subtract health directly from the SO (e.g., `data.health -= 10`), **both robots will lose health simultaneously**.

## Solution: Local State Shadowing
We shadow the SO's data with local variables on the MonoBehaviour.

### Implementation Checklist
1. **Never** write to an SO at runtime unless you explicitly want to save data across sessions (e.g., Options, Global Progress).
2. **Private Fields, Public Properties**: The SO provides the base values.
3. **Initialization Loop**:
   - `MonoBehaviour.Awake()` runs.
   - It reads `SO.Value`.
   - It sets `localValue = SO.Value`.
   - All gameplay logic (Damage, Healing) modifies `localValue`.

### Example: Damage Calculation
```csharp
public void TakeDamage(float amount) {
    // Modify the local state, NOT the SO
    currentHealth -= amount;
    
    // Use SO for static calculations if needed
    float defenseRatio = data.Armor / 100f; 
    
    if (currentHealth <= 0) Die();
}
```

## Troubleshooting
- **Values not updating in Editor?** Remember that local variables are not visible in the Inspector unless marked `[SerializeField]`.
- **NullReferenceException?** Ensure the SO reference is assigned in the Prefab's Inspector.
- **Data mismatch?** If you change the SO while the game is running, the local instances will NOT update automatically unless you implement a `Reset()` or `OnValidate()` listener.
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall