unity-core

A set of Unity and C# coding rules covering names, fields, properties, constants, and data structures. Unity is a game engine, while C# is the language used for many Unity scripts.

In plain words
What is it for?
Writing or reviewing Unity scripts, choosing names and access levels, defining serialized fields, and keeping configuration data consistent.
Why use it?
It gives the project consistent conventions and helps catch style and data-integrity problems during development.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/common-ka/ai-agent-unity-rules/unity-core
Clone the repo
git clone --depth 1 https://github.com/Common-ka/ai-agent-unity-rules

Made for: Cursor.

Per session 1,779 This file is loaded in full into every session.
When invoked 1,779 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.01779 $0.01779
Opus 5 $0.00890 $0.00890
Sonnet 5 $0.00356 $0.00356
Haiku 4.5 $0.00178 $0.00178

Measured 2d ago against content hash 3ae1f612e8ee, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

unity-core scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

Copies of this mod

1 near-identical copy found in the catalogue:

.cursor/rules/unity-core.mdc · 324 lines

How it starts

The opening of the file, as written. The whole thing — 324 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Unity Core Rules - C# & MonoBehaviour

Naming Conventions for Unity 6.2

Classes and Structs

// ✅ DO: PascalCase
public class PlayerController : MonoBehaviour { }

// ✅ DO: Readonly structs for data integrity
public readonly struct GameConfig { }

public interface IHealthSystem { }

// ❌ DON'T
public class player_controller { } // snake_case
public class playerController { } // camelCase
public struct MutableConfig { } // Avoid mutable structs

Fields and Properties

public class Example : MonoBehaviour
{
    // ✅ DO: Private fields with _ prefix (.NET Style)
    [SerializeField] private float _moveSpeed = 5f;
    private Transform _targetTransform;
    
    // ✅ DO: Public properties in PascalCase
    public float MoveSpeed => _moveSpeed;
    public bool IsMoving { get; private set; }
    
    // ✅ DO: Constants in PascalCase (Microsoft Standard)
    private const float MaxHealth = 100f;
    private const string PlayerTag = "Player";
    
    // ✅ DO: Static fields with _ prefix
    private static int _instanceCount = 0;
    
    // ✅ DO: Booleans with is/has/can prefix
    private bool _isGrounded;
    private bool _hasWeapon;
    private bool _canJump;
    
    // ❌ DON'T: Public fields without [SerializeField]
    public float moveSpeed; // Use property or [SerializeField] private
    
    // ❌ DON'T: Hungarian notation
    private float m_Speed; 
    private float fSpeed;
}

Methods and Events

public class EventExample : MonoBehaviour
{
    // ✅ DO: Methods in PascalCase
    public void ProcessInput() { }
    private void HandleCollision() { }
    
    // ✅ DO: Events with On prefix
    public event Action OnPlayerDeath;
    public event Action<int> OnScoreChanged;
    
    // ✅ DO: Async methods with Async suffix (Use Awaitable for Unity 6.2)
    private async Awaitable LoadDataAsync() { }
    public async Awaitable<bool> TryConnectAsync() { }
}

MonoBehaviour Lifecycle

Correct Method Order

public class LifecycleExample : MonoBehaviour
{
    // 1. Serialized Fields
    [SerializeField] private float _speed = 5f;
    
    // 2. Private Fields
    private Rigidbody _rigidbody;
    private bool _isInitialized;
    
    // 3. Properties
    public bool IsInitialized => _isInitialized;
    
    // 4. Unity Lifecycle Methods (in call order)
    private void Awake()
    {
        // Initialize components on this object
        // Use TryGetComponent to avoid implicit allocation if missing
        if (!TryGetComponent(out _rigidbody))
        {
            Debug.LogError("Rigidbody missing!");
        }
    }
    
    private void OnEnable()
    {
        // Subscribe to events
        GameEvents.OnLevelStart += HandleLevelStart;
    }
    
    private void Start()
    {
        // Initialization after all Awake calls
        _isInitialized = true;
    }
    
    private void FixedUpdate()
    {
        // Physics
        if (_isInitialized)
        {
            ApplyPhysics();
        }
    }
    
    private void Update()
    {
        // Game logic and input
        ProcessInput();
    }
    
    private void LateUpdate()
    {
        // Called after all Update calls (e.g., camera)
    }
    
    private void OnDisable()
    {
        // Unsubscribe from events
        GameEvents.OnLevelStart -= HandleLevelStart;
    }
    
    private void OnDestroy()
    {
        // Cleanup
        CleanupResources();
    }
    
    // 5. Custom Methods
    private void ProcessInput() { }
    private void ApplyPhysics() { }
    private void HandleLevelStart() { }
    private void CleanupResources() { }
}

Read the full file on GitHub · 324 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 324 lines · 1,779 tokens per session scan A 3ae1f612e8ee

Subscribe to this mod's changes

unity-core is a cursor rule published in the GitHub repository Common-ka/ai-agent-unity-rules (39 stars, last pushed 8mo ago), licensed MIT. It adds 1,779 tokens to every session, about $0.0089 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.