feat: Unity 2020.3 LTS support (C#8 + netstandard2.0 + 2021.2 API guards) - #1323
feat: Unity 2020.3 LTS support (C#8 + netstandard2.0 + 2021.2 API guards)#1323RoyougiShiki wants to merge 10 commits into
Conversation
- C#9 -> C#8: target-typed new(), is not, or-patterns, switch-arms (95+ sites) - .NET 2.0 API shims: Contains/Join/Range/Math.Clamp/ArgumentList etc (37 sites) - 2021.2+ Unity APIs behind #if UNITY_2021_2_OR_NEWER with equivalent 2020.3 impls: NamedBuildTarget, PrefabStageUtility (Experimental ns), subtarget, GetAllRegisteredPackages, AddAndRemoveRequest, ShaderPropertyType.Int, ProfilerCategory - New CompatDropdownField (DropdownField not in 2020.3): 2021.2+ native, 2020.3 self-drawn equivalent with UxmlFactory; 4 UXMLs migrated - Verified: Unity 2020.3.24f1 batchmode compile 0 error/0 warning, all 11 UXMLs load, window/dropdown/tool-routing runtime checks pass - docs/UNITY_2020_3_COMPAT.md: full patch inventory for sync strategy
- TestProjects/Unity2020Compat (2020.3.24f1, file: link to ../../MCPForUnity) - verify_compile.cmd one-click batchmode check (0 error / 0 warning verified) - Library/Logs/Temp gitignored
…son parsing on 2020.3 GetRegisteredPackages() 2020.3 branch used Client.List(true) + Thread.Sleep, which deadlocks the editor (PackageManager requests need main-thread pumping). New RegisteredPackageInfo helper: 2021.2+ wraps PackageInfo.GetAllRegisteredPackages(), 2020.3 parses authoritative Packages/packages-lock.json (synchronous file IO) plus best-effort package.json metadata (description/author/resolvedPath). Verified at runtime on 2020.3.24f1: 46 packages resolved, deps/metadata correct.
Rebase baseline for PR: upstream beta adds CodeDom DLL-output refactor in ExecuteCode.cs and stdio bridge timeout config; both verified compiling on Unity 2020.3.24f1 (0 errors, 0 warnings).
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe package now targets Unity 2020.3. The changes add older C# and .NET-compatible syntax, Unity API fallbacks, package metadata compatibility, process argument handling, a cross-version dropdown control, and a Unity 2020.3 compile-validation project. ChangesUnity 2020.3 compatibility
Estimated code review effort: 5 (Critical) | ~120 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 15
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
MCPForUnity/Editor/Tools/ManagePackages.cs (1)
363-384: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winHandle packages without author metadata.
RegisteredPackageInfo.GetRegisteredPackages()can returnauthor == null; its Unity package path maps a missingPackageInfo.authortodefault(MCPForUnity/Editor/Services/RegisteredPackageInfo.cs:43-144). The access at Line 384 then throws, andget_package_inforeturns an error for that package. Use a null-safe author value.The nullable behavior comes from
MCPForUnity/Editor/Services/RegisteredPackageInfo.cs.Proposed fix
- author = info.author.name, + author = info.author != null ? info.author.name : null,🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@MCPForUnity/Editor/Tools/ManagePackages.cs` around lines 363 - 384, Update the get_package_info response construction around RegisteredPackageInfo.GetRegisteredPackages() to access info.author.name null-safely, returning an appropriate empty or default author value when author metadata is missing while preserving the existing author name for packages that provide it.MCPForUnity/Editor/Tools/Graphics/LightBakingOps.cs (1)
515-529: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winDo not report an unsupported setting as changed.
On Unity versions before 2021.2, this branch returns
truewithout modifyingLightingSettings.SetSettingsthen adds the property tochangedand returns success.Return
false, or return an explicit unsupported-setting error, so callers do not treat the request as applied.Proposed fix
`#else` - return true; + return false; `#endif`🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@MCPForUnity/Editor/Tools/Graphics/LightBakingOps.cs` around lines 515 - 529, Update the pre-2021.2 branch of the lightmap compression handling in SetSettings to return false instead of reporting success, since it does not modify LightingSettings. Preserve the existing parsing and assignment behavior for Unity 2021.2 and newer so unsupported requests are not added to changed or treated as applied.MCPForUnity/Editor/Tools/Graphics/SkyboxOps.cs (1)
14-27: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick winDeclare
CustomReflectionTextureasTexture.
RenderSettings.customReflectionTextureisTexture, while legacyRenderSettings.customReflectionisCubemap. The current getter does not compile on Unity 2022.1 and newer. UseTexturefor the helper and castvalue as Cubemapin the legacy setter. Route the version-gated API access through aUnity*Compat.csshim.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@MCPForUnity/Editor/Tools/Graphics/SkyboxOps.cs` around lines 14 - 27, Change CustomReflectionTexture from Cubemap to Texture so the Unity 2022.1+ getter matches RenderSettings.customReflectionTexture. Move the version-gated RenderSettings access into the project’s Unity*Compat.cs shim, and in the legacy setter cast value as Cubemap before assigning RenderSettings.customReflection.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/UNITY_2020_3_COMPAT.md`:
- Around line 54-56: Update the PackageInfo.GetAllRegisteredPackages entry in
the UNITY_2020_3_COMPAT table to document synchronous reading of
Packages/packages-lock.json for resolved packages, replacing the incorrect
Client.List(true) polling description.
- Around line 76-80: Update the Unity 2020.3 compatibility handling for
LightingSettings.lightmapCompression writes, BuildOptions.CleanBuildCache via
clean_build, and Standalone Server subtarget requests so each unsupported
operation reports an explicit warning or error to callers instead of silently
succeeding, being ignored, or falling back to Player(0). Preserve the documented
tool behavior while exposing the compatibility limitation.
In `@MCPForUnity/Editor/Helpers/ProcessArgumentListCompat.cs`:
- Around line 13-21: Update the quoting helper used by ProcessStartInfo.AddArg
to implement standard Windows command-line argument quoting, preserving
backslashes unless they precede a quote or the closing delimiter. Ensure
arguments containing spaces, embedded quotes, and trailing backslashes
round-trip unchanged through the child-process parser, and add tests covering
each case.
In `@MCPForUnity/Editor/Security/SecureKeyStore/EncryptedFileKeyStore.cs`:
- Line 96: Update the key derivation in SecureKeyStore.TryGet to preserve
PBKDF2-SHA256 compatibility with existing files: replace the three-argument
Rfc2898DeriveBytes usage with a Unity-compatible SHA-256 implementation, or
explicitly retain the legacy SHA-256 derivation when reading and migrating files
before rewriting them.
In `@MCPForUnity/Editor/Tools/Build/BuildRunner.cs`:
- Around line 72-74: Move the version-dependent handling of options.subtarget
and clean_build out of BuildRunner and into the appropriate Unity*Compat.cs
compatibility shim. Preserve Unity 2020.3 behavior by ignoring clean_build and
using Player(0) for subtarget, while retaining the newer Unity behavior through
the shim; remove the direct version guards from the BuildRunner flow.
In `@MCPForUnity/Editor/Tools/Build/BuildSettingsHelper.cs`:
- Around line 67-71: Update the architecture mapping in the build-settings
helper to stop treating x86_64 as a valid value for the generic
PlayerSettings.GetArchitecture/SetArchitecture API, since value 0 represents
None. Remove or reject x86_64 in the write mapping, align the read mapping with
the documented architecture values, and update validation messaging accordingly;
use a target-specific API such as PlayerSettings.Android.targetArchitectures if
x86_64 support is required.
In `@MCPForUnity/Editor/Tools/Build/BuildTargetMapping.cs`:
- Around line 157-167: Update ResolveSubtarget and the BuildRunner/ManageBuild
scheduling flow so a "server" subtarget on Unity 2020.3 is rejected before the
job is scheduled, rather than silently returning 0 and leaving
BuildPlayerOptions.subtarget unset. Use a version-check shim in the MCPForUnity
runtime Unity*Compat.cs helpers, while preserving server support on Unity 2021.2
and newer.
In `@MCPForUnity/Editor/Tools/ManageBuild.cs`:
- Around line 218-222: Centralize the UNITY_2021_2_OR_NEWER standalone subtarget
compatibility logic in a Unity*Compat helper under Runtime/Helpers, exposing
read, write, and player-fallback behavior. Update the current-platform read,
platform switch, and batch-build callback in ManageBuild.cs to use that helper,
removing their direct preprocessor branches while preserving existing behavior.
- Around line 247-253: Update the subtarget handling in the build-management
method around subtargetStr so a server request on Unity versions before 2021.2
does not silently succeed with the player subtarget. Add an explicit unsupported
error for server in the older-version preprocessor branch, or ensure the
response reports player as the effective subtarget; preserve the existing
server/player assignments on Unity 2021.2 and newer.
In `@MCPForUnity/Editor/Windows/Components/CompatDropdownField.cs`:
- Around line 110-139: Update SetValueWithoutNotify and UpdateValueFromIndex to
accept and propagate a notification flag, passing false from
SetValueWithoutNotify so it updates the selected value without dispatching
callbacks. Preserve callback dispatch for normal notifying updates, matching the
Unity 2021.3 silent behavior.
In `@MCPForUnity/Editor/Windows/MCPForUnityEditorWindow.cs`:
- Around line 1061-1066: Serialize the legacy Unity Package Manager additions
instead of starting every request in the foreach loop. Update the bulk-add flow
around PollUpmAddRequest at
MCPForUnity/Editor/Windows/MCPForUnityEditorWindow.cs lines 1061-1066 and
1077-1082 to queue package IDs, start the next request only after the current
request completes successfully, and preserve completion callback behavior.
In `@TestProjects/Unity2020Compat/Packages/manifest.json`:
- Line 8: Align the Unity Test Framework dependency to one compatible version,
preferably the existing 1.1.31 required by MCPForUnity/package.json: update
TestProjects/Unity2020Compat/Packages/manifest.json and both affected
resolutions in TestProjects/Unity2020Compat/Packages/packages-lock.json (lines
15-16 and 93-102), regenerate the lock file with Unity 2020.3, then run
tools/check-unity-versions.sh.
In `@TestProjects/Unity2020Compat/README.md`:
- Around line 11-14: Update the Unity command block in the README to be runnable
interactively from cmd.exe by replacing the batch-only %~dp0 project path with
%CD% after the cd /d command, or explicitly direct users to run
verify_compile.cmd.
In `@TestProjects/Unity2020Compat/verify_compile.cmd`:
- Around line 2-3: Update verify_compile.cmd to remove hardcoded project and
Unity installation paths. Derive the project directory from %~dp0, and resolve
the Unity executable from a supplied argument or environment variable while
preserving the existing batch verification arguments.
- Around line 3-4: Update the Unity invocation and verification flow in
verify_compile.cmd to use one consistent log filename, capture Unity’s exit
status before inspecting the log, and fail when the log contains “error CS” or
does not contain “Exiting batchmode successfully now!”. Return the computed
result using exit /b, without treating compiler warnings as failures.
---
Outside diff comments:
In `@MCPForUnity/Editor/Tools/Graphics/LightBakingOps.cs`:
- Around line 515-529: Update the pre-2021.2 branch of the lightmap compression
handling in SetSettings to return false instead of reporting success, since it
does not modify LightingSettings. Preserve the existing parsing and assignment
behavior for Unity 2021.2 and newer so unsupported requests are not added to
changed or treated as applied.
In `@MCPForUnity/Editor/Tools/Graphics/SkyboxOps.cs`:
- Around line 14-27: Change CustomReflectionTexture from Cubemap to Texture so
the Unity 2022.1+ getter matches RenderSettings.customReflectionTexture. Move
the version-gated RenderSettings access into the project’s Unity*Compat.cs shim,
and in the legacy setter cast value as Cubemap before assigning
RenderSettings.customReflection.
In `@MCPForUnity/Editor/Tools/ManagePackages.cs`:
- Around line 363-384: Update the get_package_info response construction around
RegisteredPackageInfo.GetRegisteredPackages() to access info.author.name
null-safely, returning an appropriate empty or default author value when author
metadata is missing while preserving the existing author name for packages that
provide it.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 268cad2d-56b5-4346-a515-383396434c05
⛔ Files ignored due to path filters (1)
TestProjects/Unity2020Compat/compile_check.logis excluded by!**/*.log
📒 Files selected for processing (95)
MCPForUnity/Editor/Clients/McpClientConfiguratorBase.csMCPForUnity/Editor/Dependencies/PlatformDetectors/LinuxPlatformDetector.csMCPForUnity/Editor/Dependencies/PlatformDetectors/MacOSPlatformDetector.csMCPForUnity/Editor/Dependencies/PlatformDetectors/WindowsPlatformDetector.csMCPForUnity/Editor/External/Tommy.csMCPForUnity/Editor/Helpers/AssetPathUtility.csMCPForUnity/Editor/Helpers/CodexConfigHelper.csMCPForUnity/Editor/Helpers/GameObjectLookup.csMCPForUnity/Editor/Helpers/HttpEndpointUtility.csMCPForUnity/Editor/Helpers/McpConfigurationHelper.csMCPForUnity/Editor/Helpers/McpLogRecord.csMCPForUnity/Editor/Helpers/PortManager.csMCPForUnity/Editor/Helpers/ProcessArgumentListCompat.csMCPForUnity/Editor/Helpers/ProcessArgumentListCompat.cs.metaMCPForUnity/Editor/Helpers/ProjectIdentityUtility.csMCPForUnity/Editor/Helpers/UnityTypeResolver.csMCPForUnity/Editor/Helpers/VectorParsing.csMCPForUnity/Editor/Models/McpClient.csMCPForUnity/Editor/Resources/Editor/GetPrefabStage.csMCPForUnity/Editor/Security/SecureKeyStore/EncryptedFileKeyStore.csMCPForUnity/Editor/Security/SecureKeyStore/LinuxSecretToolKeyStore.csMCPForUnity/Editor/Security/SecureKeyStore/MacKeychainKeyStore.csMCPForUnity/Editor/Services/AssetGen/AssetGenJobManager.csMCPForUnity/Editor/Services/AssetGen/Import/ModelImportPipeline.csMCPForUnity/Editor/Services/AssetGen/Providers/LocalImage.csMCPForUnity/Editor/Services/EditorStateCache.csMCPForUnity/Editor/Services/IClientConfigurationService.csMCPForUnity/Editor/Services/PackageJobManager.csMCPForUnity/Editor/Services/PackageUpdateService.csMCPForUnity/Editor/Services/PathResolverService.csMCPForUnity/Editor/Services/RegisteredPackageInfo.csMCPForUnity/Editor/Services/RegisteredPackageInfo.cs.metaMCPForUnity/Editor/Services/TestJobManager.csMCPForUnity/Editor/Services/TestRunStatus.csMCPForUnity/Editor/Services/Transport/TransportCommandDispatcher.csMCPForUnity/Editor/Services/Transport/Transports/StdioBridgeHost.csMCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.csMCPForUnity/Editor/Setup/McpForUnitySkillInstaller.csMCPForUnity/Editor/Setup/SkillSyncService.csMCPForUnity/Editor/Tools/Animation/ClipCreate.csMCPForUnity/Editor/Tools/Animation/ControllerCreate.csMCPForUnity/Editor/Tools/AssetGen/AssetGenToolHelpers.csMCPForUnity/Editor/Tools/AssetGen/ImportModel.csMCPForUnity/Editor/Tools/BatchExecute.csMCPForUnity/Editor/Tools/Build/BuildJob.csMCPForUnity/Editor/Tools/Build/BuildRunner.csMCPForUnity/Editor/Tools/Build/BuildSettingsHelper.csMCPForUnity/Editor/Tools/Build/BuildTargetMapping.csMCPForUnity/Editor/Tools/Cameras/CameraCreate.csMCPForUnity/Editor/Tools/Cameras/CameraHelpers.csMCPForUnity/Editor/Tools/CommandRegistry.csMCPForUnity/Editor/Tools/ExecuteCode.csMCPForUnity/Editor/Tools/GameObjects/ComponentResolver.csMCPForUnity/Editor/Tools/GameObjects/GameObjectComponentHelpers.csMCPForUnity/Editor/Tools/GameObjects/GameObjectModify.csMCPForUnity/Editor/Tools/GameObjects/ManageGameObjectCommon.csMCPForUnity/Editor/Tools/Graphics/GraphicsHelpers.csMCPForUnity/Editor/Tools/Graphics/LightBakingOps.csMCPForUnity/Editor/Tools/Graphics/RenderPipelineOps.csMCPForUnity/Editor/Tools/Graphics/SkyboxOps.csMCPForUnity/Editor/Tools/Graphics/VolumeOps.csMCPForUnity/Editor/Tools/ManageBuild.csMCPForUnity/Editor/Tools/ManageComponents.csMCPForUnity/Editor/Tools/ManagePackages.csMCPForUnity/Editor/Tools/ManageScene.csMCPForUnity/Editor/Tools/ManageScript.csMCPForUnity/Editor/Tools/ManageScriptableObject.csMCPForUnity/Editor/Tools/ManageUI.csMCPForUnity/Editor/Tools/Prefabs/ManagePrefabs.csMCPForUnity/Editor/Tools/Profiler/Operations/CounterOps.csMCPForUnity/Editor/Tools/ReadConsole.csMCPForUnity/Editor/Tools/UnityReflect.csMCPForUnity/Editor/Tools/Vfx/ParticleControl.csMCPForUnity/Editor/Windows/Components/AssetGen/McpAssetGenSection.csMCPForUnity/Editor/Windows/Components/AssetGen/McpAssetGenSection.uxmlMCPForUnity/Editor/Windows/Components/ClientConfig/McpClientConfigSection.csMCPForUnity/Editor/Windows/Components/ClientConfig/McpClientConfigSection.uxmlMCPForUnity/Editor/Windows/Components/CompatDropdownField.csMCPForUnity/Editor/Windows/Components/CompatDropdownField.cs.metaMCPForUnity/Editor/Windows/Components/Resources/McpResourcesSection.csMCPForUnity/Editor/Windows/Components/Tools/McpToolsSection.csMCPForUnity/Editor/Windows/EditorPrefs/EditorPrefItem.uxmlMCPForUnity/Editor/Windows/EditorPrefs/EditorPrefsWindow.csMCPForUnity/Editor/Windows/EditorPrefs/EditorPrefsWindow.uxmlMCPForUnity/Editor/Windows/MCPForUnityEditorWindow.csMCPForUnity/Editor/Windows/MCPSetupWindow.csMCPForUnity/Runtime/Serialization/UnityTypeConverters.csMCPForUnity/package.jsonTestProjects/Unity2020Compat/.gitignoreTestProjects/Unity2020Compat/Packages/manifest.jsonTestProjects/Unity2020Compat/Packages/packages-lock.jsonTestProjects/Unity2020Compat/ProjectSettings/ProjectVersion.txtTestProjects/Unity2020Compat/README.mdTestProjects/Unity2020Compat/verify_compile.cmddocs/UNITY_2020_3_COMPAT.md
| | `UIDocument` runtime UI 组件(attach_ui_document / detach_ui_document / get_visual_tree / render_ui / modify_visual_element / create_panel_settings / update_panel_settings) | 2021.2+ 才有 | 返回明确错误信息 "requires Unity 2021.2 or newer",工具列表仍注册 | | ||
| | `LightingSettings.lightmapCompression` | 2021.2+ 才有 | 读取省略该字段,写入静默跳过 | | ||
| | `BuildOptions.CleanBuildCache` | 2021.2+ 才有 | clean_build 参数被忽略 | | ||
| | Standalone Server 子目标构建 | 2021.2+ 才有 | subtarget 固定为 Player(0) | | ||
| | `ProfilerCategory.FileIO` / `VirtualTexturing` | 2021.2+ 才有 | 映射到相近分类 | |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n -C 5 'lightmapCompression|clean_build|Standalone|subtarget|unsupported|warning|error' \
MCPForUnity/Editor/Tools/Graphics/LightBakingOps.cs \
MCPForUnity/Editor/Tools/Build/BuildRunner.cs \
MCPForUnity/Editor/Tools/Build/BuildSettingsHelper.csRepository: CoplayDev/unity-mcp
Length of output: 7062
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- documentation ---'
sed -n '60,90p' docs/UNITY_2020_3_COMPAT.md
printf '%s\n' '--- LightBakingOps handlers and callers ---'
rg -n -C 8 'Get|Set|lightmapCompression|SetLight|HandleCommand|return false|return true' \
MCPForUnity/Editor/Tools/Graphics/LightBakingOps.cs
printf '%s\n' '--- BuildRunner callers and result handling ---'
rg -n -C 10 'CreateBuildOptions|clean_build|subtarget|BuildPipeline.BuildPlayer|BuildReport|BuildSummary|return' \
MCPForUnity/Editor/Tools/Build/BuildRunner.cs \
MCPForUnity/Editor/Tools/Build/BuildSettingsHelper.cs \
MCPForUnity/Editor/Tools/BuildRepository: CoplayDev/unity-mcp
Length of output: 50376
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- build tool call sites ---'
rg -l 'CreateBuildOptions|ParseBuildOptions|subtarget|clean_build' MCPForUnity/Editor/Tools/Build
rg -n -C 12 'CreateBuildOptions|ParseBuildOptions|subtarget|clean_build' MCPForUnity/Editor/Tools/Build --glob '*.cs' \
| grep -E '^(MCPForUnity|--|[0-9])' | head -n 240
printf '%s\n' '--- response models and unsupported-result conventions ---'
rg -n -C 5 'class ErrorResponse|class PendingResponse|unsupported|requires Unity|warnings|warning|success =' \
MCPForUnity/Editor --glob '*.cs' | head -n 260Repository: CoplayDev/unity-mcp
Length of output: 32113
Make unsupported operations visible to callers.
On Unity 2020.3, lightmapCompression writes return success without applying the value. clean_build is ignored. Standalone Server requests resolve to the Player subtarget. Return explicit unsupported warnings or errors.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docs/UNITY_2020_3_COMPAT.md` around lines 76 - 80, Update the Unity 2020.3
compatibility handling for LightingSettings.lightmapCompression writes,
BuildOptions.CleanBuildCache via clean_build, and Standalone Server subtarget
requests so each unsupported operation reports an explicit warning or error to
callers instead of silently succeeding, being ignored, or falling back to
Player(0). Preserve the documented tool behavior while exposing the
compatibility limitation.
| #if UNITY_2021_2_OR_NEWER | ||
| options.subtarget = subtarget; | ||
| #endif |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
rg -n -C 5 \
'clean_build|CleanBuildCache|subtarget|StandaloneBuildSubtarget' \
MCPForUnity docs TestProjects \
--glob '*.cs' --glob '*.md'Repository: CoplayDev/unity-mcp
Length of output: 14980
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
printf '%s\n' '--- BuildRunner.cs ---'
sed -n '1,125p' MCPForUnity/Editor/Tools/Build/BuildRunner.cs
printf '%s\n' '--- compatibility documentation ---'
sed -n '1,100p' docs/UNITY_2020_3_COMPAT.md
printf '%s\n' '--- compatibility helpers ---'
fd -i 'Unity.*Compat\.cs' MCPForUnity/Runtime/Helpers MCPForUnity/Editor 2>/dev/null | sort
rg -n -C 4 'CleanBuildCache|BuildPlayerOptions|subtarget|StandaloneBuildSubtarget' \
MCPForUnity/Runtime/Helpers MCPForUnity/Editor/Tools/Build \
--glob '*.cs'Repository: CoplayDev/unity-mcp
Length of output: 16601
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
printf '%s\n' '--- compatibility helper implementations ---'
for f in $(fd -i 'Unity.*Compat\.cs' MCPForUnity 2>/dev/null | sort); do
echo "--- $f"
sed -n '1,180p' "$f"
done
printf '%s\n' '--- assembly definitions and version-check tooling ---'
fd -i -E Library -E Temp -E Packages \
'.*(asmdef|check-unity-versions\.sh)$' . 2>/dev/null | sort
rg -n -C 3 'Unity.*Compat|UNITY_2021_2_OR_NEWER|BuildOptions\.CleanBuildCache|BuildPlayerOptions' \
MCPForUnity --glob '*.asmdef' --glob '*.cs' --glob '*.sh' | head -300Repository: CoplayDev/unity-mcp
Length of output: 46306
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
printf '%s\n' '--- assembly references ---'
cat MCPForUnity/Runtime/MCPForUnity.Runtime.asmdef
cat MCPForUnity/Editor/MCPForUnity.Editor.asmdef
printf '%s\n' '--- shim policy ---'
sed -n '1,90p' MCPForUnity/Runtime/Helpers/UnityCompatShims.csRepository: CoplayDev/unity-mcp
Length of output: 3568
Route version-dependent build APIs through a compatibility shim. Unity 2020.3 intentionally ignores clean_build and uses Player(0) for subtarget; this behavior is documented, so no warning or error is needed. Move both guards into MCPForUnity/Runtime/Helpers/Unity*Compat.cs.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@MCPForUnity/Editor/Tools/Build/BuildRunner.cs` around lines 72 - 74, Move the
version-dependent handling of options.subtarget and clean_build out of
BuildRunner and into the appropriate Unity*Compat.cs compatibility shim.
Preserve Unity 2020.3 behavior by ignoring clean_build and using Player(0) for
subtarget, while retaining the newer Unity behavior through the shim; remove the
direct version guards from the BuildRunner flow.
| "com.unity.ide.rider": "2.0.7", | ||
| "com.unity.ide.visualstudio": "2.0.12", | ||
| "com.unity.ide.vscode": "1.2.4", | ||
| "com.unity.test-framework": "1.1.29", |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
manifest='TestProjects/Unity2020Compat/Packages/manifest.json'
lock='TestProjects/Unity2020Compat/Packages/packages-lock.json'
jq -r '.dependencies["com.unity.test-framework"]' "$manifest"
jq -r '.dependencies["com.coplaydev.unity-mcp"].dependencies["com.unity.test-framework"]' "$lock"
jq -r '.dependencies["com.unity.test-framework"] | {version, depth}' "$lock"Repository: CoplayDev/unity-mcp
Length of output: 211
🏁 Script executed:
#!/bin/bash
set -euo pipefail
manifest='TestProjects/Unity2020Compat/Packages/manifest.json'
lock='TestProjects/Unity2020Compat/Packages/packages-lock.json'
printf '%s\n' '--- Unity 2020 compatibility project ---'
find 'TestProjects/Unity2020Compat' -maxdepth 3 -type f \
\( -name 'manifest.json' -o -name 'packages-lock.json' -o -name 'package.json' -o -name 'ProjectVersion.txt' \) \
-print
printf '%s\n' '--- Relevant package declarations ---'
cat -n "$manifest" | sed -n '1,30p'
cat -n "$lock" | sed -n '1,120p'
printf '%s\n' '--- Local package metadata ---'
rg -n -C 4 '"com\.unity\.test-framework"|test-framework' \
TestProjects/Unity2020Compat Packages MCPForUnity 2>/dev/null || true
printf '%s\n' '--- Unity version-check script references ---'
if [ -f tools/check-unity-versions.sh ]; then
cat -n tools/check-unity-versions.sh
else
printf '%s\n' 'tools/check-unity-versions.sh is not present'
fiRepository: CoplayDev/unity-mcp
Length of output: 22666
🌐 Web query:
Unity Package Manager packages-lock.json direct dependency depth manifest exact version lock file behavior Unity 2020.3
💡 Result:
In Unity 2020.3, the packages-lock.json file serves as a deterministic record of the entire dependency graph for a project, including both direct and indirect dependencies [1][2][3]. It is automatically generated and maintained by the Unity Package Manager to ensure that the exact same package versions are installed across different machines, providing reliability and performance improvements by avoiding redundant dependency resolution and downloads [1][2]. Key aspects of its behavior include: 1. Dependency Depth and Graph Storage: The lock file tracks the full dependency graph [2][3]. While the project manifest (manifest.json) stores only the top-level direct dependencies, the lock file records the specific versions of all indirect dependencies required to satisfy the project's requirements [4][5]. Because packages can have their own dependencies, the lock file structure reflects this hierarchical depth [4]. 2. Determinism and Locking: As long as a package's version in the lock file remains compatible with the constraints defined in the manifests and the project's current resolution strategy, the Package Manager will keep the package locked at that specific version [1][3]. This prevents unexpected version shifts when a project is opened on different machines [4][6]. 3. Maintenance and Manual Modification: The Package Manager exclusively manages the packages-lock.json file [1]. Users should not manually modify it, as the Package Manager will overwrite any manual changes during its next resolution pass [1]. 4. Refreshing Dependencies: If you need to force the Package Manager to recalculate the dependency graph—for example, to update indirect dependencies to the latest compatible versions—you can delete the packages-lock.json file [1]. The Package Manager will then regenerate it upon the next successful resolution [1]. 5. Source Control: It is recommended practice to commit the packages-lock.json file to source control to ensure consistent environments for all team members [4][1]. 6. Configuration: The use of the lock file is enabled by default [1][7]. If desired, it can be disabled by setting the enableLockFile property to false in the project's manifest.json, though this is generally discouraged as it can lead to non-deterministic results and increased network usage [1].
Citations:
- 1: https://docs.unity3d.com/2020.3/Documentation/Manual/upm-conflicts-auto.html
- 2: https://docs.unity3d.com/2020.3/Documentation/Manual/upm-dependencies.html
- 3: https://docs.unity3d.com/2020.3/Documentation/Manual/upm-conflicts.html
- 4: https://gamedev.stackexchange.com/questions/183870/what-is-the-package-lock-json-file-for-in-unity
- 5: https://docs.unity3d.com/6000.3/Documentation/Manual/upm-manifestPrj.html
- 6: https://docs.unity3d.com/2020.3/Documentation/Manual/upm-git.html
- 7: https://docs.unity3d.com/2020.3/Documentation/Manual/upm-manifestPrj.html
🌐 Web query:
site:docs.unity3d.com/2020.3 "Package Manager resolves conflicts" direct dependency version dependency exact
💡 Result:
Package managers resolve version conflicts between direct and transitive (indirect) dependencies by constructing a comprehensive dependency graph that includes all requested packages [1][2]. Because a package manager can typically install only one version of a specific package at a time, it must evaluate all dependency requirements—both explicit direct dependencies defined in the project manifest and recursive transitive dependencies defined by those packages—to find a version that satisfies all constraints [1][2]. When conflicts arise, the resolution process generally follows these principles: 1. Consistency and Determinism: Package managers often use a lock file (such as packages-lock.json) to store the successfully resolved dependency graph [1][3]. This ensures that future installations produce the same results and avoids redundant computations [2][3]. 2. Version Selection Strategies: If multiple versions of a package are requested, the manager attempts to find a single version that falls within all specified version ranges [2]. If the manager cannot satisfy all constraints, it often defaults to a least-risky upgrade path, such as preferring patch updates over minor or major version changes [2][3]. 3. Configuration and Control: Users can often influence this resolution process. For example, some systems allow for the configuration of resolution strategies (e.g., forcing lowest versions or allowing higher compatible versions) to manage how strictly the manager adheres to requested versions [4][3]. While it is technically possible to resolve conflicts by explicitly adding an indirect dependency to the project manifest to override a version, this is generally considered a suboptimal practice compared to configuring resolution strategies [4]. In essence, the package manager functions as a solver that calculates a set of versions that satisfies all direct and indirect requirements simultaneously [2]. If a valid intersection of all version requirements exists, it selects a version—often the highest compatible one based on defined strategies—and locks that selection to maintain project stability [2][4][3].
Citations:
- 1: https://docs.unity3d.com/2020.3/Documentation/Manual/upm-dependencies.html
- 2: https://docs.unity3d.com/2020.3/Documentation/Manual/upm-conflicts.html
- 3: https://docs.unity3d.com/2020.3/Documentation/Manual/upm-conflicts-auto.html
- 4: https://docs.unity3d.com/2020.3/Documentation/Manual/upm-manifestPrj.html
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
import json
from pathlib import Path
manifest_path = Path("TestProjects/Unity2020Compat/Packages/manifest.json")
lock_path = Path("TestProjects/Unity2020Compat/Packages/packages-lock.json")
package_path = Path("MCPForUnity/package.json")
manifest = json.loads(manifest_path.read_text())
lock = json.loads(lock_path.read_text())
package = json.loads(package_path.read_text())
name = "com.unity.test-framework"
direct = manifest["dependencies"].get(name)
local_req = package["dependencies"].get(name)
locked = lock["dependencies"].get(name, {})
local_lock_req = lock["dependencies"]["com.coplaydev.unity-mcp"]["dependencies"].get(name)
print({
"manifest_direct": direct,
"local_package_requirement": local_req,
"lock_local_requirement": local_lock_req,
"lock_version": locked.get("version"),
"lock_depth": locked.get("depth"),
"direct_lock_entry": locked.get("depth") == 0,
"manifest_matches_lock": direct == locked.get("version"),
"local_requirement_matches_lock": local_req == locked.get("version"),
"lock_requirement_matches_local_package": local_lock_req == local_req,
})
PYRepository: CoplayDev/unity-mcp
Length of output: 453
Align the Unity Test Framework dependency graph.
manifest.json requests 1.1.29, but MCPForUnity/package.json and packages-lock.json require and resolve 1.1.31. Select one compatible version, regenerate the lock file with Unity 2020.3, and run tools/check-unity-versions.sh.
📍 Affects 2 files
TestProjects/Unity2020Compat/Packages/manifest.json#L8-L8(this comment)TestProjects/Unity2020Compat/Packages/packages-lock.json#L15-L16TestProjects/Unity2020Compat/Packages/packages-lock.json#L93-L102
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@TestProjects/Unity2020Compat/Packages/manifest.json` at line 8, Align the
Unity Test Framework dependency to one compatible version, preferably the
existing 1.1.31 required by MCPForUnity/package.json: update
TestProjects/Unity2020Compat/Packages/manifest.json and both affected
resolutions in TestProjects/Unity2020Compat/Packages/packages-lock.json (lines
15-16 and 93-102), regenerate the lock file with Unity 2020.3, then run
tools/check-unity-versions.sh.
Source: Learnings
- ProcessArgumentListCompat: correct Windows command-line quoting (backslash runs doubled only before quotes/at end; verbatim pass-through when unquoted) - EncryptedFileKeyStore: implement PBKDF2-HMAC-SHA256 manually on 2020.3 (netstandard2.1 lacks 4-arg Rfc2898DeriveBytes) so key derivation stays byte-identical with 2021.2+; 3-arg SHA1 would break existing ciphertext MAC - CompatDropdownField: SetValueWithoutNotify no longer dispatches change events - MCPForUnityEditorWindow: 2020.3 package add/remove serialized via queue (legacy PM accepts one in-flight request per operation) - BuildSettingsHelper: architecture mapping fixed (0 = None, not x86_64) - ManageBuild: 'server' subtarget rejected on <2021.2 instead of silent player - docs: correct packages-lock.json description; test project: align test-framework 1.1.31, portable verify_compile.cmd (auto-detect Unity, exit codes, consistent log), README command block
|
Thanks for the thorough review! All actionable findings addressed in Fixed:
Deferred with rationale (kept as-is for this PR):
|
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@MCPForUnity/Editor/Security/SecureKeyStore/EncryptedFileKeyStore.cs`:
- Around line 106-109: Correct the target framework reference in the comment
above the manual PBKDF2-HMAC-SHA256 implementation: identify Unity 2020.3 as
using netstandard2.0 instead of netstandard2.1, while preserving the explanation
of why the manual derivation is required.
In `@MCPForUnity/Editor/Tools/ManageBuild.cs`:
- Around line 253-259: Update the build-target flow around the active-target
return and subtarget handling so `subtarget` is validated and applied before the
short circuit. On Unity 2020.3, reject `server` requests before returning for an
already-active target; on Unity 2021.2+, apply both `server` and `player`
through `standaloneBuildSubtarget`. Keep the existing `SwitchActiveBuildTarget`
skip only when the target is already active.
In `@TestProjects/Unity2020Compat/verify_compile.cmd`:
- Around line 45-46: Update verify_compile.cmd after the Unity invocation and
UNITY_STATUS capture to fail immediately when UNITY_STATUS is nonzero, before
evaluating any log markers or reporting PASS. Preserve the existing log
validation for successful Unity executions.
- Line 27: Update the UNITY_EXE detection condition to use %%~E for both the
existence check and assignment, ensuring the stored executable path excludes
surrounding quotes and later command usage does not produce double-quoted paths.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: e196bae5-ec85-40f8-b1a0-50b4e8ae6bce
📒 Files selected for processing (11)
MCPForUnity/Editor/Helpers/ProcessArgumentListCompat.csMCPForUnity/Editor/Security/SecureKeyStore/EncryptedFileKeyStore.csMCPForUnity/Editor/Tools/Build/BuildSettingsHelper.csMCPForUnity/Editor/Tools/ManageBuild.csMCPForUnity/Editor/Windows/Components/CompatDropdownField.csMCPForUnity/Editor/Windows/MCPForUnityEditorWindow.csTestProjects/Unity2020Compat/Packages/manifest.jsonTestProjects/Unity2020Compat/Packages/packages-lock.jsonTestProjects/Unity2020Compat/README.mdTestProjects/Unity2020Compat/verify_compile.cmddocs/UNITY_2020_3_COMPAT.md
🚧 Files skipped from review as they are similar to previous changes (7)
- TestProjects/Unity2020Compat/README.md
- docs/UNITY_2020_3_COMPAT.md
- TestProjects/Unity2020Compat/Packages/packages-lock.json
- TestProjects/Unity2020Compat/Packages/manifest.json
- MCPForUnity/Editor/Windows/MCPForUnityEditorWindow.cs
- MCPForUnity/Editor/Tools/Build/BuildSettingsHelper.cs
- MCPForUnity/Editor/Windows/Components/CompatDropdownField.cs
- verify_compile.cmd: use %%~E to strip quotes from detected Unity path (%%E kept surrounding quotes -> double-quoted executable); fail when Unity exits nonzero before accepting log markers - ManageBuild: process subtarget before the active-target short-circuit so a 'server' request on <2021.2 errors even when platform is already active - EncryptedFileKeyStore: correct comment (netstandard2.0, not 2.1)
|
Second round addressed in
|
|
These four comments reference the pre-
Verified compiling on Unity 2020.3.24f1 (0 errors / 0 warnings). Ready for the next review round on |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@TestProjects/Unity2020Compat/verify_compile.cmd`:
- Line 27: Quote the operand of the if exist check in the %%E loop so paths
containing spaces are handled correctly, while keeping the UNITY_EXE assignment
based on the unquoted %%~E value.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: f3d3cf43-157e-46d9-a492-8a9ae9f6df12
📒 Files selected for processing (3)
MCPForUnity/Editor/Security/SecureKeyStore/EncryptedFileKeyStore.csMCPForUnity/Editor/Tools/ManageBuild.csTestProjects/Unity2020Compat/verify_compile.cmd
🚧 Files skipped from review as they are similar to previous changes (2)
- MCPForUnity/Editor/Tools/ManageBuild.cs
- MCPForUnity/Editor/Security/SecureKeyStore/EncryptedFileKeyStore.cs
%%~E strips quotes for the assignment; the if exist check needs its own quotes to handle spaces in default Hub paths (C:\Program Files\...). Verified with a space-path test on cmd.exe.
|
Addressed in (Note: Blinter's |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
TestProjects/Unity2020Compat/verify_compile.cmd (2)
9-9: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winCorrect the documented exit code contract.
Exit code
1also covers Unity startup failure, a missing log, and an unclean shutdown. Document it as1 = verification failed, or list the individual failure cases.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@TestProjects/Unity2020Compat/verify_compile.cmd` at line 9, Update the exit-code documentation in verify_compile.cmd to state that code 1 means verification failed, covering compile errors, Unity startup failure, missing logs, and unclean shutdown; retain the existing meanings for codes 0 and 2.
17-20: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy liftValidate that the selected editor is Unity 2020.3.
The command-line argument and
UNITY_EDITORvalue are accepted after only an existence check. A caller can provide Unity 2021.3 or a newer editor, and the script can report success without compiling under Unity 2020.3. Reject editors outside the 2020.3 line, or verify the editor version from its output before running the check.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@TestProjects/Unity2020Compat/verify_compile.cmd` around lines 17 - 20, Update the editor-selection logic in verify_compile.cmd to validate that the chosen UNITY_EXE, whether supplied by %~1 or UNITY_EDITOR, is Unity 2020.3 before compiling. Reject or fail clearly for other editor versions, including newer releases, rather than proceeding with verification.
🧹 Nitpick comments (2)
TestProjects/Unity2020Compat/verify_compile.cmd (2)
45-46: 🩺 Stability & Availability | 🔵 Trivial | 🏗️ Heavy liftProvide a timeout for the Unity process.
Line 45 blocks until Unity exits. If Unity hangs during import, licensing, or project reload, the verification job can hang indefinitely. Confirm that the calling CI job has an outer timeout, or add a timeout and process-termination path here.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@TestProjects/Unity2020Compat/verify_compile.cmd` around lines 45 - 46, Update the Unity invocation in the verification script to enforce a finite timeout and terminate the Unity process when it exceeds that limit, while preserving capture of its exit status in UNITY_STATUS. If timeout handling is provided by the calling CI job instead, confirm and rely on that documented outer timeout rather than leaving the process unbounded.
41-71: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRun the cross-version compatibility check before merge.
This script validates one selected editor. Run
tools/check-unity-versions.shto compile-check the supported Unity version matrix, including newer Unity versions.Based on learnings: “When modifying Unity version shims or gated code, run
tools/check-unity-versions.shto compile-check across the CI matrix before committing.”🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@TestProjects/Unity2020Compat/verify_compile.cmd` around lines 41 - 71, Run tools/check-unity-versions.sh to compile-check the complete supported Unity version matrix, including newer editors, before committing or merging changes to Unity compatibility code; keep verify_compile.cmd focused on validating its selected editor.Source: Learnings
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@TestProjects/Unity2020Compat/verify_compile.cmd`:
- Line 9: Update the exit-code documentation in verify_compile.cmd to state that
code 1 means verification failed, covering compile errors, Unity startup
failure, missing logs, and unclean shutdown; retain the existing meanings for
codes 0 and 2.
- Around line 17-20: Update the editor-selection logic in verify_compile.cmd to
validate that the chosen UNITY_EXE, whether supplied by %~1 or UNITY_EDITOR, is
Unity 2020.3 before compiling. Reject or fail clearly for other editor versions,
including newer releases, rather than proceeding with verification.
---
Nitpick comments:
In `@TestProjects/Unity2020Compat/verify_compile.cmd`:
- Around line 45-46: Update the Unity invocation in the verification script to
enforce a finite timeout and terminate the Unity process when it exceeds that
limit, while preserving capture of its exit status in UNITY_STATUS. If timeout
handling is provided by the calling CI job instead, confirm and rely on that
documented outer timeout rather than leaving the process unbounded.
- Around line 41-71: Run tools/check-unity-versions.sh to compile-check the
complete supported Unity version matrix, including newer editors, before
committing or merging changes to Unity compatibility code; keep
verify_compile.cmd focused on validating its selected editor.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 95bdfbab-b565-482a-98b6-0333e221e968
📒 Files selected for processing (1)
TestProjects/Unity2020Compat/verify_compile.cmd
…ix note - Exit code 1 documented as 'verification failed' (compile errors, startup failure, missing log, unclean exit) - Non-2020.3 editors get a clear warning (path-based 2020.3 check) instead of silently passing - this project validates the 2020.3 floor - PASS output notes tools/check-unity-versions.sh for the full matrix
|
Round 4 addressed in
Skipped with rationale: in-script timeout/termination for the Unity process — this script is a local/CI helper where the caller already bounds the job (our runs use an outer timeout); adding |
Summary
Enable Unity 2020.3 LTS support for MCP for Unity. The package currently requires 2021.3+; this PR lowers the floor to 2020.3 by removing C# 9 syntax and shimming .NET Core 2.1+ / Unity 2021.2+ APIs that 2020.3 lacks.
All changes are behavior-neutral on 2021.3+: newer Unity versions take the same code paths as before (guarded with
#if UNITY_2021_2_OR_NEWER), and the 2020.3 branches are functionally equivalent implementations, not stubs.Verified on Unity 2020.3.24f1: full package compile with 0 errors / 0 warnings, all 11 UXML files load, editor windows open, dropdown control + tool routing runtime checks pass. A dedicated test project is included (
TestProjects/Unity2020Compat).What changed
1. C# 9 → C# 8 (2020.3 ships the C# 8 compiler)
new()/new(...)→ explicit types (~65 sites)is not T xpattern →!(x is T x)(20 sites)is A or B/ property-patternorcombos → equivalent boolean expressionsorarms → split arms; target-typed ternaries → explicitIMcpResponsecasts2. .NET API shims (netstandard2.0 vs 2.1)
string.Contains(char),Contains(str, StringComparison),string.Join(char, …)→ netstandard2.0 equivalentsIndex/Rangeslicing (s[..^n]) →SubstringMath.Clamp→Mathf.Clamp,Task.IsCompletedSuccessfully→TaskStatus.RanToCompletionDictionary.Remove(k, out v)→TryGetValue+RemoveProcessStartInfo.ArgumentList→ newAddArg()extension (argument-quoting equivalent)Path.GetRelativePath,Enum.TryParse(Type,…)4-arg,Rfc2898DeriveBytes4-arg → 2020.3-compatible equivalents3. Unity 2021.2+ APIs behind version guards (2020.3 branches are equivalents, not stubs)
NamedBuildTarget→BuildTargetGroup(2020.3 has all the same PlayerSettings overloads)PrefabStage/PrefabStageUtility→UnityEditor.Experimental.SceneManagement(moved in 2021.2),OpenPrefab→AssetDatabase.OpenAsset+GetCurrentPrefabStagePackageInfo.GetAllRegisteredPackages()→ newRegisteredPackageInfohelper: 2021.2+ wraps the native API; 2020.3 parses authoritativePackages/packages-lock.json(synchronous file IO — the alternativeClient.Listpolling deadlocks the editor, see commit 3c690f0)Client.AddAndRemove→ per-packageAdd/Remove;StandaloneBuildSubtarget/CleanBuildCacheguarded4. UI Toolkit
DropdownField(2021.2+) → newCompatDropdownField: 2021.2+ inheritsDropdownFieldunchanged; 2020.3 self-draws an equivalent popup (PopupField<string> keepschoicesprivate) with UxmlFactory/UxmlTraits. 4 UXML files updated.5. Documented 2020.3-only gaps (no equivalent API exists anywhere in 2020.3)
UIDocumentruntime UI tools return an explicit "requires Unity 2021.2+" error (tools stay registered)LightingSettings.lightmapCompression,BuildOptions.CleanBuildCache, standalone Server subtarget,ProfilerCategory.FileIO/VirtualTexturing→ guarded/skipped on 2020.3Notes for maintainers
docs/UNITY_2020_3_COMPAT.mdTestProjects/Unity2020Compat(2020.3.24f1,file:link to../../MCPForUnity, one-clickverify_compile.cmd)Summary by CodeRabbit
New Features
Bug Fixes
Documentation