home / skills / dev-gom / claude-code-marketplace / unity-script-validator

This skill validates Unity C# scripts for best practices and performance, offering fixes, impact estimates, and refactored examples.

npx playbooks add skill dev-gom/claude-code-marketplace --skill unity-script-validator

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
1.9 KB
---
name: Unity Script Validator
description: Validates C# scripts for best practices, performance, and Unity patterns. Use when reviewing scripts or checking code quality.
allowed-tools: Read, Grep, Glob
---

# Unity Script Validator

Validates Unity C# scripts against best practices and performance patterns specific to Unity game development.

## What This Skill Checks

- **Field declarations**: `[SerializeField] private` instead of public fields
- **Component caching**: GetComponent in Awake/Start, not Update (~100x faster)
- **String operations**: StringBuilder for frequent concatenation
- **GameObject.Find**: Cache references, avoid in Update (O(n) operation)
- **Code organization**: #region directives, consistent ordering
- **XML documentation**: `<summary>` tags on public methods
- **Update vs FixedUpdate**: Appropriate usage for physics/non-physics
- **Coroutines**: Prefer for intermittent tasks over Update

Provides: Issues found, specific fixes, performance impact estimates, refactored code examples.

## Compatibility

Applies to Unity 2019.4 LTS and later (including Unity 6).

See [patterns.md](patterns.md) and [examples.md](examples.md) for detailed optimization techniques.

## When to Use vs Other Components

**Use this Skill when**: Quick validation of existing Unity scripts for best practices and common issues

**Use @unity-scripter agent when**: Writing new code or implementing Unity features from scratch

**Use @unity-refactor agent when**: Improving code quality, applying design patterns, or modernizing legacy code

**Use @unity-performance agent when**: Deep performance profiling, memory optimization, or platform-specific tuning

**Use /unity:new-script command when**: Creating new scripts from production-ready templates

## Related Skills

- **unity-scene-optimizer**: For scene-level performance analysis
- **unity-template-generator**: For generating validated script templates

Overview

This skill validates C# Unity scripts for best practices, common anti-patterns, and performance issues specific to Unity projects. It provides actionable findings, estimated performance impacts, and small refactor examples to speed code reviews and reduce runtime costs. Use it to catch costly patterns early and enforce consistent Unity conventions across a codebase.

How this skill works

The validator scans scripts for patterns such as public fields that should be [SerializeField] private, costly operations in Update (e.g., GetComponent, GameObject.Find), and inefficient string concatenation. For each issue it reports a description, the likely performance impact, and a suggested fix. It can also suggest organization improvements (regions, ordering) and missing XML <summary> comments for public APIs.

When to use it

  • Quick code review of existing Unity C# scripts before merging
  • Automated validation as part of CI to catch regressions
  • Prior to performance testing to remove obvious runtime hotspots
  • During refactoring to ensure Unity-specific best practices are applied
  • When auditing legacy scripts for modernization opportunities

Best practices

  • Mark serialized fields as [SerializeField] private to preserve encapsulation
  • Cache GetComponent, transforms, and references in Awake/Start rather than Update
  • Avoid GameObject.Find in Update; resolve references at initialization
  • Use StringBuilder for repeated string concatenation in loops or frequent updates
  • Use Coroutines for intermittent timed work instead of polling in Update
  • Use FixedUpdate only for physics-related updates; keep rendering logic in Update

Example use cases

  • Scan a gameplay script and get a list of Update-time GetComponent/GameObject.Find calls with fixes
  • Identify public fields that should be serialized privately and generate the refactored field declarations
  • Suggest replacing frequent string concatenation in UI updates with StringBuilder and show before/after code
  • Flag missing XML <summary> on public methods to improve API documentation
  • Recommend coroutine conversion for a timer loop that currently runs in Update

FAQ

Which Unity versions are supported?

The validator targets Unity 2019.4 LTS and later, including current Unity 6 compatibility.

Does it automatically modify my code?

It provides concrete refactored examples and suggested edits but does not change files automatically unless integrated with a code-mod tool.