Fix CS0618 by wrapping deprecated Find APIs in #if guards#41
Merged
Conversation
Wrap all uses of the obsolete Object.FindObjectOfType<T>() and Object.FindObjectsOfType<T>() in #if directives to maintain backward compatibility while resolving CS0618 errors introduced by treating the warning as an error in Default.globalconfig. - FindObjectOfType → FindFirstObjectByType (2-way guard, UNITY_2022_3_OR_NEWER) - FindObjectsOfType → FindObjectsByType (3-way guard, adds UNITY_6000_4_OR_NEWER to drop the obsolete FindObjectsSortMode argument) - Remove #pragma warning disable CS0618 from MonoBehaviourTestExample.cs - Bump copyright year to 2026 in all modified files Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
…ity 6.4 Unity 6.4 (6000.4) deprecated FindFirstObjectByType because it relies on instance ID ordering, which is being migrated to EntityId. Adding a UNITY_6000_4_OR_NEWER preprocessor branch using FindAnyObjectByType (the Unity-recommended replacement) to all 9 singular Find sites across 7 test files. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
95e9ce9 to
ae2c412
Compare
Code Metrics Report
Details | | master (338eb5a) | #41 (2b9efe9) | +/- |
|---------------------|------------------|---------------|------|
| Coverage | 40.3% | 40.3% | 0.0% |
| Files | 25 | 25 | 0 |
| Lines | 478 | 478 | 0 |
| Covered | 193 | 193 | 0 |
+ | Code to Test Ratio | 1:3.9 | 1:4.0 | +0.0 |
| Code | 1255 | 1255 | 0 |
+ | Test | 5001 | 5048 | +47 |
- | Test Execution Time | 4m30s | 4m42s | +12s |Reported by octocov |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Assets/Default.globalconfigto treat CS0618 (obsolete member usage) as a compiler error, surfacing all deprecatedObject.FindObjectOfType<T>()/Object.FindObjectsOfType<T>()calls across the project#ifdirectives to maintain backward compatibility while adopting the modern APIs on supported Unity versions:FindObjectOfType<T>()→FindFirstObjectByType<T>()(2-way guard:UNITY_2022_3_OR_NEWER)FindObjectsOfType<T>()→FindObjectsByType<T>(...)(3-way guard: addsUNITY_6000_4_OR_NEWERto drop the obsoleteFindObjectsSortModeargument, which itself becomes obsolete in 6000.4)#pragma warning disable CS0618fromMonoBehaviourTestExample.cs(now unnecessary)Affected files
Assets/Default.globalconfigAssets/SceneExample/Tests/Runtime/NestedComponentTest.csAssets/SceneExample/Tests/Editor/EditorSceneManagerTest.csAssets/InputExample/Tests/Runtime/FirstPersonControllerLegacyTest.csAssets/InputSystemExample/Tests/Runtime/FirstPersonControllerTest.csAssets/InputSystemExample/Tests/Runtime/MonkeyTest.csAssets/InputSystemExample/Tests/Runtime/ScenarioTest.csAssets/BasicExample/Tests/Editor/Validators/LevelValidator.csAssets/APIExamples/Tests/Runtime/UnityTestFramework/MonoBehaviourTestExample.csTest plan
APIExamples.Editorasync examples (unrelated to this change)SceneExample,InputExample,InputSystemExample,BasicExample,UGUIExample,VisualRegressionExample,LocalPackageSample,EmbeddedPackageSample)MonoBehaviourTestExamplePlayMode: 2/2 pass🤖 Generated with Claude Code