StemCode for Unity Developers: AI Coding with C# and real project context.

Set up StemCode for Unity projects with C# scripts, Assets, Packages, ProjectSettings, Unity command-line automation, testing, refactoring, and Git review.

PUBLISHED 2026-10-01STEMCODE DEVELOPER GUIDELOCAL-FIRST AI CODING
PROJECT INSTRUCTIONS / AGENTS.MD

Give StemCode durable repository instructions before asking it to edit.

Add an AGENTS.md file at the repository root for persistent project instructions. StemCode loads AGENTS.md or .agent/AGENTS.md from the workspace into the model context, so this is the right place for architecture boundaries, generated-file rules, coding conventions, validation expectations, and manual setup notes that should apply across sessions.

Keep AGENTS.md practical and repository-specific

Prefer concrete rules the agent can act on: where important source lives, what it must not edit, which patterns it should preserve, and which checks it should run after a change.

# Unity Project Instructions

This is a Unity project.

Important source and configuration paths:
- Assets/Scripts/
- Assets/
- Packages/
- ProjectSettings/
- *.asmdef
- *.cs

Generated or disposable paths — do not modify:
- Library/
- Temp/
- Obj/
- Logs/
- UserSettings/
- Build/
- Builds/

Follow these rules:
- This is a Unity C# project.
- Main gameplay scripts are under Assets/Scripts/.
- Use standard Unity C# conventions.
- Prefer components over large monolithic scripts.
- Do not modify Library/, Temp/, Obj/, Logs/, UserSettings/, or generated build output.
- Do not modify scene or prefab YAML manually unless specifically requested.
- Preserve existing serialized field names unless a rename is intentional.
- Check for Unity lifecycle implications when changing Awake, Start, Update, FixedUpdate, OnEnable, and OnDisable.
- Keep runtime and Editor-only code separated.
- Explain required Inspector setup after creating or changing a component.
- Avoid introducing packages unless they are necessary.
- Use the project's checked-in Unity CLI wrapper or exact Editor version for automated validation.
- After modifying C# code, check for likely Unity compilation errors and run relevant tests.

Validation:
- "<UnityEditor>" -batchmode -projectPath . -runTests -testPlatform EditMode -testResults TestResults/editmode.xml -logFile -
- "<UnityEditor>" -batchmode -projectPath . -runTests -testPlatform PlayMode -testResults TestResults/playmode.xml -logFile -
- Use the same Unity build or test wrapper used by CI when available

Commit the file with the project so the same instructions are reviewable and shared by everyone using StemCode in the repository.

01 / WHY STEMCODE

Use repository-aware AI without replacing the tools your stack already needs.

StemCode works best when it can understand the repository around a task, inspect related files, use code intelligence where available, run the project's normal validation commands, and review the final diff before you accept a change.

GOOD FIT FOR UNITY WORK

Unity games and interactive applications using C#, MonoBehaviour components, ScriptableObjects, editor tooling, packages, Edit Mode and Play Mode tests, prefabs, scenes, Unity command-line automation, and normal Git workflows.

02 / SETUP

Install StemCode and open the project root.

Install StemCode separately from Unity, then launch it from the Unity project root. Keep using the Unity Editor for scene authoring, Inspector work, profiling, Play Mode, package management, and platform builds.

npmnpm install -g stemcode
pnpmpnpm add -g stemcode
cd your-project
stemcode
/init

Keep StemCode at the repository root so project instructions, source, configuration, tests, and Git history are visible from one workspace.

03 / PROJECT CONTEXT

Give the agent Unity source and settings without flooding it with generated files.

A useful Unity workspace includes authored assets, C# code, package manifests, and project settings. Unity also produces large generated directories that usually add noise to repository search.

INSPECT

Keep source-of-truth files visible.

Assets/Scripts/
Assets/
Packages/
ProjectSettings/
*.asmdef
*.cs
IGNORE

Skip generated or disposable output.

Library/
Temp/
Obj/
Logs/
UserSettings/
Build/
Builds/

Add generated paths to Git ignore rules or .stemcode/.stemcodeignore so repository search stays focused.

FIRST PROMPT

Understand the project before changing it.

Analyze this Unity project. Identify the important scenes, assemblies, gameplay systems, ScriptableObjects, editor code, packages, and test layout. Explain how the main runtime systems connect. Do not modify files yet.

04 / CODE INTELLIGENCE

Use C# language intelligence alongside Unity-aware repository search.

Unity C# projects benefit from definitions, references, diagnostics, and symbol navigation. A C# language server can complement repository search when gameplay code is spread across assemblies and packages.

CSHARP-LSdotnet tool install --global csharp-ls
/lsp refresh
/lsp
Use both semantic navigation and repository search

Use semantic navigation for C# symbols, but keep Unity-specific context in view: serialized fields, assembly definitions, package boundaries, editor-only code, and lifecycle methods such as Awake, OnEnable, Start, Update, and FixedUpdate can change behavior even when a refactor compiles.

05 / NATIVE CLI

Use the Unity Editor executable as the project CLI.

Unity does not require a separate project CLI package: the Editor executable accepts command-line arguments for unattended imports, tests, custom build methods, and CI. Use the exact Editor version declared by the project and keep its machine-specific path in an environment variable or repository script instead of hard-coding it into prompts.

EDIT MODE TESTS"<UnityEditor>" -batchmode -projectPath . -runTests -testPlatform EditMode -testResults TestResults/editmode.xml -logFile -
PLAY MODE TESTS"<UnityEditor>" -batchmode -projectPath . -runTests -testPlatform PlayMode -testResults TestResults/playmode.xml -logFile -
CUSTOM BUILD"<UnityEditor>" -batchmode -quit -projectPath . -executeMethod BuildScript.PerformBuild -logFile -

Replace <UnityEditor> with the Editor executable for the project’s installed Unity version. Keep custom build entry points in Editor code, make them deterministic, and prefer a checked-in wrapper script such as scripts/unity-test or scripts/unity-build so StemCode and CI invoke the same command.

06 / DEVELOPMENT WORKFLOW

Separate C# implementation from Editor-owned scene and asset work.

Ask StemCode to change scripts and text configuration precisely, then use the Unity Editor for visual authoring and validation. Be cautious with serialized YAML and binary assets.

FEATURE

Add a gameplay system

Trace existing gameplay patterns, then implement a player health system under the current architecture. Reuse existing events and UI patterns, add tests where the project already uses them, and list any Inspector wiring required afterward.

REFACTOR

Change lifecycle code safely

Review this MonoBehaviour hierarchy for duplicated Update work, hidden allocations, event subscription leaks, and execution-order assumptions. Propose a small refactor before editing.

EDITOR

Respect Unity-owned assets

Implement the C# side of this feature without manually rewriting scene or prefab YAML unless the repository already treats those files as reviewed source and the change is explicitly required.

BUG

Trace runtime behavior

Trace this bug from input through component state, physics or animation interactions, and scene dependencies. Explain the likely cause before modifying code.

07 / BUILD AND TEST

Use Unity tests and project compilation as the source of truth.

Prefer the checked-in Unity CLI wrapper or CI command used by the project. If none exists yet, start from Unity batch mode and Test Framework commands, then commit a small wrapper so local developers, StemCode, and CI share one validation path.

EDIT MODE"<UnityEditor>" -batchmode -projectPath . -runTests -testPlatform EditMode -testResults TestResults/editmode.xml -logFile -
PLAY MODE"<UnityEditor>" -batchmode -projectPath . -runTests -testPlatform PlayMode -testResults TestResults/playmode.xml -logFile -
CIUse the same Unity build or test wrapper used by CI when available

After C# edits, confirm that Unity imports and recompiles cleanly, then run the smallest relevant Edit Mode or Play Mode tests and exercise the affected scene in the Editor. Build or platform validation should follow the project’s existing automation.

Run the smallest relevant validation first. If it passes, run the broader project checks and review the final diff.
08 / PROJECT MEMORY

Keep longer-lived architecture context alongside your project instructions.

Use AGENTS.md for concise rules the agent should follow on every task. Keep longer architecture notes, domain context, and workflow references in repository-level StemCode memory so both stay reviewable and versionable.

This is a Unity C# project.
Main gameplay scripts are under Assets/Scripts/.
Use standard Unity C# conventions.
Prefer components over large monolithic scripts.
Do not modify Library/, Temp/, Obj/, Logs/, UserSettings/, or generated build output.
Do not modify scene or prefab YAML manually unless specifically requested.
Preserve existing serialized field names unless a rename is intentional.
Check for Unity lifecycle implications when changing Awake, Start, Update, FixedUpdate, OnEnable, and OnDisable.
Keep runtime and Editor-only code separated.
Explain required Inspector setup after creating or changing a component.
Avoid introducing packages unless they are necessary.
Use the project's checked-in Unity CLI wrapper or exact Editor version for automated validation.
After modifying C# code, check for likely Unity compilation errors and run relevant tests.
09 / REVIEW

Review the change in terms of your stack, not only the generated code.

Ask StemCode to inspect its own diff and check the integration points that are easiest to miss in a repository-wide change.

- Unity lifecycle and execution-order regressions
- lost serialized references or renamed serialized fields
- runtime versus Editor assembly boundaries
- per-frame allocations and unnecessary Update work
- event subscription and cleanup symmetry
- required Inspector or scene setup
- Edit Mode or Play Mode test coverage
- Unity CLI or CI validation results
10 / FAQ

Common setup questions.

Does Unity have a command-line workflow?

Yes. The Unity Editor executable accepts command-line arguments such as -batchmode, -projectPath, -runTests, -testPlatform, -testResults, and -executeMethod. Use the project’s exact Editor version and preferably wrap the command in a checked-in script.

Can StemCode control the Unity Editor directly?

The normal repository workflow focuses on project files and commands. Direct Editor actions require an appropriate Unity editor integration or MCP tool; keep visual scene and Inspector work in Unity unless such tooling is intentionally connected.

Should Library be indexed?

Usually no. Library is generated and can be very large. Keep Assets, Packages, and ProjectSettings visible and ignore generated Unity directories.

Can it edit scenes and prefabs?

Unity scenes and many prefabs are serialized text when text serialization is enabled, but they are easy to damage with blind edits. Prefer Editor-driven changes unless the repository already reviews those files as source and the requested change is well scoped.

NEXT STEP

Put StemCode to work in a real repository.

Install StemCode, open the project you already work in, and begin with a repository-understanding task before asking the agent to change code. That gives the model better context and keeps the workflow reviewable.

INSTALL

Start with the CLI.

npm install -g stemcode
cd your-project
stemcode
LEARN

Go deeper.

Read the full StemCode documentation for providers, permissions, LSP integrations, memory, MCP, CI review, and advanced workspace configuration.

READ THE DOCS →