Skip to content

fix: support Unity 2022.2 object lookup compatibility#1089

Open
chenkunqing wants to merge 1 commit intoCoplayDev:betafrom
chenkunqing:codex-fix-unity-2022-findobjects-compat
Open

fix: support Unity 2022.2 object lookup compatibility#1089
chenkunqing wants to merge 1 commit intoCoplayDev:betafrom
chenkunqing:codex-fix-unity-2022-findobjects-compat

Conversation

@chenkunqing
Copy link
Copy Markdown
Contributor

@chenkunqing chenkunqing commented Apr 27, 2026

Description

Fix a Unity 2022.2 compatibility issue in UnityFindObjectsCompat.

Some Unity 2022.2 editor versions do not reliably expose the newer object lookup APIs used by the package. This caused compilation failures in projects using Unity 2022.2.1f1.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Changes Made

  • Delayed use of Object.FindObjectsByType(...) until UNITY_2022_3_OR_NEWER
  • Delayed use of Object.FindAnyObjectByType(...) until UNITY_2022_3_OR_NEWER
  • Kept FindObjectsOfType(...) / FindObjectOfType(...) as the fallback path for Unity 2022.2.x
  • Added local pragma guards for obsolete fallback APIs to keep the compatibility wrapper warning-clean

Testing/Screenshots/Recordings

  • Reproduced the compile failure on Unity 2022.2.1f1
  • Verified the project compiles cleanly in Unity 2022.2.1f1 after the compatibility change
  • Ran git diff --check

Documentation Updates

  • I have added/removed/modified tools or resources
  • If yes, I have updated all documentation files using:
    • The LLM prompt at tools/UPDATE_DOCS_PROMPT.md (recommended)
    • Manual updates following the guide at tools/UPDATE_DOCS.md

Related Issues

Relates to Unity 2022.2.x compilation failures in UnityFindObjectsCompat.

Additional Notes

This change intentionally keeps the fix minimal and only adjusts the version gating for object lookup APIs in the compatibility helper.

Summary by CodeRabbit

  • Chores
    • Updated Unity compatibility layer to utilize newer APIs for Unity 2022.3+ while maintaining backward compatibility with older versions.
    • Enhanced code stability with improved warning handling for legacy code paths.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 27, 2026

📝 Walkthrough

Walkthrough

The compatibility wrapper for Unity object finding is updated to use newer FindObjectsByType APIs starting with Unity 2022.3 instead of 2022.2, with pragma directives added to suppress obsolete API warnings in legacy code paths. Documentation is simplified to reflect the single version threshold.

Changes

Cohort / File(s) Summary
Unity Compatibility Version Gating
MCPForUnity/Runtime/Helpers/UnityFindObjectsCompat.cs
Changed API cutover threshold from UNITY_2022_2_OR_NEWER to UNITY_2022_3_OR_NEWER for FindObjectsByType usage. Added #pragma warning disable/restore 618 directives around fallback code paths to suppress obsolete API warnings. Documentation updated to remove fine-grained version breakdown and simplify to single threshold statement.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A hop through the versions, we've made our way,
From 2022.2 to 2023 today,
With pragmas in place to hush the old cry,
Our objects find swiftly as time passes by! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding support for Unity 2022.2 by adjusting version gates in the compatibility layer.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description is comprehensive and well-structured, following the template with all required sections completed.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant