A framework for hardened Unity/C# development optimized for AI assistance.
Carbide Unity provides coding standards, patterns, and Claude Code slash commands designed to help developers write safe, maintainable, and performant Unity code with AI assistance.
- Prescriptive over Permissive - Clear rules are easier to follow than vague guidelines
- Explicit over Implicit - Null handling, event lifecycle, and ownership should be obvious
- Validated over Assumed - Patterns that catch issues early
- Simple over Clever - Readable code beats clever optimizations
- Performant by Default - Patterns avoid common Unity performance pitfalls
Use the review commands immediately on any Unity project:
/carbide-unity-review Assets/Scripts/Player.cs
/carbide-unity-safety Assets/Scripts/
/carbide-unity-init MyGame
This creates a complete project structure with:
- Assembly definitions for fast compilation
- Folder structure following best practices
- Starter scripts (GameManager, Events)
- Script templates
| Document | Purpose |
|---|---|
| CARBIDE_UNITY.md | Quick reference for AI development |
| STANDARDS.md | Complete coding standards |
| docs/patterns/performance.md | Object pooling, GC avoidance, optimization |
| docs/patterns/architecture.md | ScriptableObject events, state machines, DI |
| docs/safety/common-pitfalls.md | Null refs, event leaks, threading issues |
| Command | Mode | Purpose |
|---|---|---|
/carbide-unity-init |
Setup | Create new Carbide-compliant Unity projects |
/carbide-unity-review |
Standalone | Review code against naming, memory, lifecycle standards |
/carbide-unity-safety |
Standalone | Security-focused review for crashes, leaks, race conditions |
public class PlayerController : MonoBehaviour // PascalCase class
{
[SerializeField] private float _moveSpeed; // _camelCase private field
public event Action OnDeath; // On + PascalCase event
private bool _isGrounded; // is/has/can prefix for bools
public void TakeDamage(int amount) { } // PascalCase method
}private void Awake() // Cache own components
private void OnEnable() // Subscribe to events
private void Start() // Setup requiring other objects
private void OnDisable() // Unsubscribe from events
private void OnDestroy() // Final cleanup- No allocations in Update - No
new, LINQ, or string concatenation - Cache everything - GetComponent in Awake, not Update
- Pool frequently instantiated objects - Never Instantiate/Destroy in loops
- Use NonAlloc methods -
Physics.RaycastNonAlloc, notPhysics.RaycastAll
private void OnEnable()
{
GameEvents.OnGamePaused += HandlePause; // Subscribe
}
private void OnDisable()
{
GameEvents.OnGamePaused -= HandlePause; // Always unsubscribe!
}- Copy slash commands to your project's
.claude/commands/folder - Reference Carbide Unity in your project's
CLAUDE.md:
# MyGame
This project follows [Carbide Unity](/path/to/CarbideUnity) standards.Run /carbide-unity-init to scaffold a complete project structure.
MIT License - See LICENSE