Skip to content

Fix CS0618 by wrapping deprecated Find APIs in #if guards#41

Merged
nowsprinting merged 5 commits into
masterfrom
chore/cs0618-to-error
Jun 27, 2026
Merged

Fix CS0618 by wrapping deprecated Find APIs in #if guards#41
nowsprinting merged 5 commits into
masterfrom
chore/cs0618-to-error

Conversation

@nowsprinting

Copy link
Copy Markdown
Owner

Summary

  • Added Assets/Default.globalconfig to treat CS0618 (obsolete member usage) as a compiler error, surfacing all deprecated Object.FindObjectOfType<T>() / Object.FindObjectsOfType<T>() calls across the project
  • Wrapped each call in #if directives 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: adds UNITY_6000_4_OR_NEWER to drop the obsolete FindObjectsSortMode argument, which itself becomes obsolete in 6000.4)
  • Removed #pragma warning disable CS0618 from MonoBehaviourTestExample.cs (now unnecessary)
  • Bumped copyright year to 2026 in all modified files

Affected files

File Change
Assets/Default.globalconfig New — promotes CS0618 to error
Assets/SceneExample/Tests/Runtime/NestedComponentTest.cs 2-way guard
Assets/SceneExample/Tests/Editor/EditorSceneManagerTest.cs 2-way guard (×2)
Assets/InputExample/Tests/Runtime/FirstPersonControllerLegacyTest.cs 2-way guard
Assets/InputSystemExample/Tests/Runtime/FirstPersonControllerTest.cs 2-way guard
Assets/InputSystemExample/Tests/Runtime/MonkeyTest.cs 2-way guard
Assets/InputSystemExample/Tests/Runtime/ScenarioTest.cs 2-way guard
Assets/BasicExample/Tests/Editor/Validators/LevelValidator.cs 3-way guard (×2)
Assets/APIExamples/Tests/Runtime/UnityTestFramework/MonoBehaviourTestExample.cs 2-way guard (×2) + remove pragma

Test plan

  • Unity compilation succeeds with zero CS0618 errors (verified on Unity 6000.0.43f1)
  • EditMode tests: all pass except pre-existing failures in APIExamples.Editor async examples (unrelated to this change)
  • PlayMode tests: all pass for modified assemblies (SceneExample, InputExample, InputSystemExample, BasicExample, UGUIExample, VisualRegressionExample, LocalPackageSample, EmbeddedPackageSample)
  • MonoBehaviourTestExample PlayMode: 2/2 pass

🤖 Generated with Claude Code

nowsprinting and others added 4 commits June 27, 2026 07:28
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>
@nowsprinting nowsprinting changed the title Fix CS0618 errors by wrapping deprecated Find APIs in #if guards Fix CS0618 by wrapping deprecated Find APIs in #if guards Jun 26, 2026
@github-actions

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>
@nowsprinting nowsprinting force-pushed the chore/cs0618-to-error branch from 95e9ce9 to ae2c412 Compare June 27, 2026 00:00
@github-actions

Copy link
Copy Markdown

Code Metrics Report

master (338eb5a) #41 (2b9efe9) +/-
Coverage 40.3% 40.3% 0.0%
Code to Test Ratio 1:3.9 1:4.0 +0.0
Test Execution Time 4m30s 4m42s +12s
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

@nowsprinting nowsprinting merged commit 0558116 into master Jun 27, 2026
11 checks passed
@nowsprinting nowsprinting deleted the chore/cs0618-to-error branch June 27, 2026 00:07
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