Blog
Programming
RealXP Lab Unity C# Style Guide
We’re sharing our internal standards to help you write cleaner, more professional code.
RealXP Lab
Jul 2, 2025
This is the official RealXP Lab document that outlines how we write and structure Unity C# code. It's meant to promote clarity and consistency across our projects, and help externs build strong habits around clean, professional code.
This guide draws inspiration from:
Formatting Guidelines
Naming conventions
PascalCase: Names of namespaces, classes, structs, methods, enumerations, properties, files, directories, public fields, and constant fields
camelCase: Names of local variables and method parameters
_camelCase: Names of private, protected, internal and protected internal instance fields (no
m_,s_, ork_prefixes)Always explicitly specify access modifiers (e.g.
private,public,internal)Variables: Use nouns. Be descriptive and avoid abbreviations. (e.g.
playerHealth,enemyCount,scoreMultiplier)Units: Add units to measurable quantities (e.g.
rotationRadians,transitionSeconds,colorFactor0To1)Booleans: Prefix with a verb (e.g.
isAnimated,hasPowerUp,canJump)Enums: Use singular nouns (e.g.
WeaponType)Bitwise enums marked with
[System.Flags]are the exception — use plural names (e.g.AttackModes)
Avoid redundant naming: Don’t repeat the class name in member names unnecessarily (e.g. use
Scoreinstead ofPlayerScoreinside aPlayerclass)Methods: Prefix with a verb (e.g.
StartGame(),GetDirection())Methods returning
boolshould ask a question (e.g.IsGameOver(),HasStartedTurn())
Interfaces: Prefix with capital
Ifollowed by a descriptive adjective or phrase (e.g.IDamageable,ISaveable)Events:
Use verb phrases to name events, and make sure they clearly describe the state change
Use the present participle (e.g.
OpeningDoor) to indicate an event that occurs before the action completesUse the past participle (e.g.
DoorOpened) to indicate an event that occurs after the action has completedUse the
System.Actiondelegate by default. Only define customEventArgstypes when necessaryPrefix event raising methods with
On(e.g.OnDoorOpened())Prefix event handler methods with the subject name and underscore (e.g.
GameEvents_DoorOpened)
MonoBehaviour files: File name must match the MonoBehaviour class. Only one MonoBehaviour per file
Whitespace rules
Use Allman style (brace on a new line)
Indentation: 4 spaces, no tabs
Keep line lengths under 120 characters
Always use braces, even for one-line
if/elseOne declaration per line:
int health;One statement per line
One assignment per statement
Space before flow conditions:
if (x == y)No space between method name and parentheses:
Jump()No space inside array brackets:
items[i]Space after commas:
DoSomething(x, y, z)No space after opening or before closing parentheses:
DoSomething(x)No space after a cast:
var x = (float)y
Organization
Use namespaces to prevent naming conflicts with global or external types
Add
usingdirectives at the top of the file to avoid repeated namespace referencesAlways place
Systemimports first, then sort the rest alphabeticallyStrip unused
usingdirectives - keep only the minimally required set
Organize class members in the following order:
Fields
Properties
Events
Unity methods (Awake, Start, Update, OnControllerColliderHit, etc.)
Public methods
Private methods
Nested classes or structs
Avoid
#regionunless absolutely necessary
Comments & inspector attributes
Avoid commenting obvious logic, prefer self-documenting names and structure
Assume the what is clear from the code; use comments to explain why—intent or reasoning
Start with a capital letter and avoid periods unless it's a full sentence
Use
TODOcomments to mark follow-ups, pair it with a ticket or owner when possibleAvoid leaving commented-out code in PRs, use version control
Use
// --- SECTION NAME ---(ALL CAPS label, three hyphens each side) to mark logical sections if neededUse XML summary tags for all public types (classes, structs, enums, interfaces) and public methods
Use one inspector attribute per line. Place attributes immediately above the member, without blank lines
Prefer
[Tooltip]over code comments for fields exposed in the InspectorFor auto-properties, use
[field: SerializeField]to expose the backing field while maintaining encapsulation
Coding Guidelines
Constants & readonly
Use
constwhere possible; otherwise usereadonlyPrefer named constants to magic numbers
Collections & types
For method inputs, use the most restrictive collection types (
IEnumerable<T>,IReadOnlyList<T>, etc.)Use
List<T>for outputs unless lazy evaluation is neededPrefer
List<T>over arrays unless size is fixed, data is multidimensional, or required
Tuples & return types
Prefer named classes over
Tuple<>for return typesConsider return objects for complex/multi-value returns
Strings
Prefer string interpolation for readability (e.g.
$"Score: {playerScore}")Prefer a reused
StringBuilderin hot paths that build large/variable text.
LINQ & delegates
Avoid long LINQ chains, prefer readability
Prefer method/extension syntax over LINQ query expressions (e.g.
Where()overfrom...in...where)Avoid
.ForEach()on lists unless it's a one-linerAvoid LINQ in methods that run every frame (
Update,FixedUpdate, etc.)Use
?.Invoke()to call delegates
Extension methods
Prefer adding directly to class, use extension methods only when modifying source is not possible
Limit extensions to general-purpose methods
Structs vs classes
Use structs only for small, immutable, short-lived types
Default to class unless performance or memory constraints justify struct
Miscellaneous
Use
== nullfor null checks overis nullorobject.ReferenceEquals(x, null)Use
varonly when the type is obvious from contextPrefer
switchover longif-elsechains when appropriateAvoid excessively long methods and large parameter lists
Avoid method overloading unless necessary
Example
RealXP Lab
Share
