Unity-MCP unity-version-split
Split a C# file into Unity 6.5+ and pre-Unity 6.5 variants. Use when a file needs different implementations for different Unity versions due to API changes (e.g., EntityId vs int, GetEntityId vs GetInstanceID).
git clone https://github.com/IvanMurzak/Unity-MCP
T=$(mktemp -d) && git clone --depth=1 https://github.com/IvanMurzak/Unity-MCP "$T" && mkdir -p ~/.claude/skills && cp -r "$T/Unity-MCP-Plugin/.claude/skills/unity-version-split" ~/.claude/skills/ivanmurzak-unity-mcp-unity-version-split && rm -rf "$T"
Unity-MCP-Plugin/.claude/skills/unity-version-split/SKILL.mdUnity Version Split
Split a C# source file into two variants: one for Unity 6.5+ (
UNITY_6000_5_OR_NEWER) and one for older versions (pre-Unity 6.5).
When to Use
Unity 6.5 introduced breaking changes including:
replacesEntityId
for instance IDs (int
replacesGetEntityId()
)GetInstanceID()
replacesEditorUtility.EntityIdToObject(EntityId)EditorUtility.InstanceIDToObject(int)- Implicit
conversions are markedEntityId <-> int
(compile error)[Obsolete(..., true)]
When a file needs different code for these Unity versions, split it into two files following the project convention.
File Naming Convention
| File | Purpose | Preprocessor Guard |
|---|---|---|
| Unity 6.5+ (newer version) | |
| Pre-Unity 6.5 (older version) | |
For files that also have Editor/Runtime variants, combine the guards:
| File | Guard |
|---|---|
| |
| |
| |
| |
Step-by-Step Process
Step 1 — Read the Source File
Read
$ARGUMENTS (the target file path). Identify which parts need version-specific code.
Step 2 — Identify the Split Points
Common differences between Unity 6.5+ and pre-6.5:
| Unity 6.5+ | Pre-Unity 6.5 |
|---|---|
| |
| |
| |
| |
is | is |
Step 3 — Create the Two Files
-
Update the original
file to contain only the Unity 6.5+ version:.cs- Set the preprocessor guard to include
UNITY_6000_5_OR_NEWER - Use
,EntityId
, etc.GetEntityId()
- Set the preprocessor guard to include
-
Create the
file with the pre-6.5 version:.pre-Unity.6.5.cs- Set the preprocessor guard to include
!UNITY_6000_5_OR_NEWER - Use
,int
, etc.GetInstanceID()
- Set the preprocessor guard to include
Both files must:
- Start with
#nullable enable - Have the same copyright header as the original
- Use the same namespace and class name (partial classes)
- End with
matching the opening#endif#if
Step 4 — Refresh Assets
Run
assets-refresh tool to let Unity generate .meta files and recompile.
IMPORTANT: Do NOT manually create
files. Unity auto-generates them after .meta
assets-refresh or any AssetDatabase.Refresh() call.
Step 5 — Verify
Check for compilation errors using
console-get-logs tool.
Example
Given
GameObjectUtils.Runtime.cs with #if !UNITY_EDITOR that uses both EntityId and int with #if UNITY_6000_5_OR_NEWER inside:
Before (single file with nested #if):
#if !UNITY_EDITOR // ... #if UNITY_6000_5_OR_NEWER public static GameObject? FindByInstanceID(EntityId instanceID) { ... } #else public static GameObject? FindByInstanceID(int instanceID) { ... } #endif #endif
After (two clean files):
GameObjectUtils.Runtime.cs:
#if !UNITY_EDITOR && UNITY_6000_5_OR_NEWER // ... public static GameObject? FindByInstanceID(EntityId instanceID) { ... } #endif
GameObjectUtils.Runtime.pre-Unity.6.5.cs:
#if !UNITY_EDITOR && !UNITY_6000_5_OR_NEWER // ... public static GameObject? FindByInstanceID(int instanceID) { ... } #endif
Reference Files
Existing examples of this pattern in the codebase:
/Runtime/Data/ObjectRef.csObjectRef.pre-Unity.6.5.cs
/Runtime/Data/GameObjectRef.csGameObjectRef.pre-Unity.6.5.cs
/Runtime/Utils/GameObjectUtils.Editor.csGameObjectUtils.Editor.pre-Unity.6.5.cs
/Tests/Editor/Tool/Assets/AssetsPrefabCreateTests.csAssetsPrefabCreateTests.pre-Unity.6.5.cs