Source metadata

  • Type: Official Unity e-book
  • Maintainer: Unity
  • Date on source page: 2025-01-21
  • Primary URL: C# Code Style Guide

Key takeaways

  • Unity treats code style as a question of team productivity. Predictable names and file structures reduce cognitive load when many people work on the same project.
  • The guide keeps coming back to small methods and small classes, and prefers them to large scripts that mix several responsibilities.
  • It recommends shared configuration such as EditorConfig as a practical way to keep formatting consistent across IDEs and version control.
  • Style guidance extends to UI Toolkit naming, where Unity pushes teams towards web-like conventions for UXML, USS and related assets.

Notable claims

  • Style conventions are most useful when the whole team applies them consistently. Left to personal taste, they lose that value.
  • Naming and method structure affect readability, debugging speed and onboarding as well as how the code looks.
  • UI Toolkit needs explicit naming discipline because the code, the UXML and the USS have to stay aligned.

Relevance

The guide is the main source for csharp-code-style. Its advice on keeping methods short supports csharp-methods, and its UI Toolkit naming section supports unity-ui-toolkit.

Open questions raised

  • How strictly should the wiki prescribe Unity-flavoured naming conventions over general C# conventions?
  • Which parts of the guide are strong defaults, and which should stay as preferences each team sets for itself?