fix warning: use unity 6 api when compiling for unity 6#298
fix warning: use unity 6 api when compiling for unity 6#298ggStrider wants to merge 1 commit intomodesttree:masterfrom
Conversation
tigran-sargsyan-w
left a comment
There was a problem hiding this comment.
Summary
Fixes Unity 6 compiler warnings by switching from FindObjectsOfType to the new FindObjectsByType API behind #if UNITY_6000 guards in ProjectContext.cs and UnityUtil.cs.
Strengths
- Minimal, targeted change; preserves behavior on older Unity versions.
- Correctly uses the
FindObjectsByType<T>(FindObjectsSortMode.None)overload to avoid sorting overhead. - Reduces noise from obsolete API warnings in 6000.x without altering runtime logic.
Suggestions
-
Preprocessor symbol
Consider usingUNITY_6000_0_OR_NEWER(or evenUNITY_2023_1_OR_NEWER) if you want to enable the new API for earlier versions whereFindObjectsByTypealready exists, and to be future-proof with Unity’s common_OR_NEWERconvention. -
Namespace clarity (minor)
If there are files that alsousing System;, you could qualifyObjectasUnityEngine.Objectfor clarity (purely stylistic; not blocking). -
Behavior parity note
The old calls (FindObjectsOfTypewithout parameters) return only active objects; the new calls here should match that. If any callers relied on inactive objects, consider the overload withFindObjectsInactive.Include. (Looks fine as-is forProjectContextand the scene enumeration use-case.)
looks good overall; the_OR_NEWERdefine would make it a bit more robust.
Thank you for sending a pull request! Please make sure you read the contribution guidelines
Pull request checklist
Please check if your PR fulfills the following requirements:
Pull request type
Please check the type of change your PR introduces:
Issue Number
Issue Number: N/A
What is the current behavior?
Using obsolete API in Unity 6 causes compiler warnings.
What is the new behavior?
When compiling with UNITY_6000 defined, the new Unity 6 API is used,
eliminating obsolete warnings while keeping compatibility with older Unity versions.
Does this introduce a breaking change?
Other information
This PR only adds a conditional compilation check to use the Unity 6 API.
No functional changes are introduced for other Unity versions.
On which Unity version has this been tested?
Scripting backend: