-
Notifications
You must be signed in to change notification settings - Fork 462
chore: update usage of deprecated FindObjectsByType<T>(FindObjectsSortMode) and enum FindObjectSortMode #3857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NoelStephensUnity
wants to merge
16
commits into
develop-2.0.0
Choose a base branch
from
chore/findobjectsbytype-no-more-sorting-update
base: develop-2.0.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b5bff02
update
NoelStephensUnity 793bade
update
NoelStephensUnity c8f54c9
update
NoelStephensUnity a5719db
update
NoelStephensUnity fec5e65
style
NoelStephensUnity db390f5
Update com.unity.netcode.gameobjects/Runtime/Core/FindObjects.cs
NoelStephensUnity 9a5d04b
update
NoelStephensUnity a5983f7
update
NoelStephensUnity b52e907
Merge branch 'develop-2.0.0' into chore/findobjectsbytype-no-more-sor…
NoelStephensUnity 1f7e70c
update
NoelStephensUnity 01dd8c0
style
NoelStephensUnity b53de7a
update
NoelStephensUnity 1a5bb4a
update
NoelStephensUnity f5f5cf2
update
NoelStephensUnity 9939aa6
Merge branch 'develop-2.0.0' into chore/findobjectsbytype-no-more-sor…
NoelStephensUnity 5b4f42d
update
NoelStephensUnity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #if NGO_FINDOBJECTS_NOSORTING | ||
| using System; | ||
| #endif | ||
| using System.Runtime.CompilerServices; | ||
| using Object = UnityEngine.Object; | ||
|
|
||
| namespace Unity.Netcode | ||
| { | ||
| /// <summary> | ||
| /// Helper class to handle the variations of FindObjectsByType. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// It is intentional that we do not include the UnityEngine namespace in order to avoid | ||
| /// over-complicatd define wrapping between versions that do or don't support FindObjectsSortMode. | ||
| /// </remarks> | ||
| internal static class FindObjects | ||
| { | ||
| /// <summary> | ||
| /// Replaces <see cref="Object.FindObjectsByType"/> to have one place where these changes are applied. | ||
| /// </summary> | ||
| /// <typeparam name="T"></typeparam> | ||
| /// <param name="includeInactive">When true, inactive objects will be included.</param> | ||
| /// <param name="orderByIdentifier">When true, the array returned will be sorted by identifier.</param> | ||
| /// <returns>Resulst as an <see cref="Array"/> of type T</returns> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static T[] ByType<T>(bool includeInactive = false, bool orderByIdentifier = false) where T : Object | ||
| { | ||
| var inactive = includeInactive ? UnityEngine.FindObjectsInactive.Include : UnityEngine.FindObjectsInactive.Exclude; | ||
| #if NGO_FINDOBJECTS_NOSORTING | ||
| var results = Object.FindObjectsByType<T>(inactive); | ||
| if (orderByIdentifier) | ||
| { | ||
| Array.Sort(results, (a, b) => a.GetEntityId().CompareTo(b.GetEntityId())); | ||
| } | ||
| #else | ||
| var results = Object.FindObjectsByType<T>(inactive, orderByIdentifier ? UnityEngine.FindObjectsSortMode.InstanceID : UnityEngine.FindObjectsSortMode.None); | ||
| #endif | ||
| return results; | ||
| } | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
com.unity.netcode.gameobjects/Runtime/Core/FindObjects.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you implemented this retro-compatibility fix to avoid compilation errors on alpha/beta versions that didn't have the deprecation change yet, but do we intend to support those versions in the long run?
The risk I foresee is that we fill our code with a bunch of defines for "almost-dead code", with an increased maintenance burden for us, and higher rissk to introduce bugs as we have to support multiple workflows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making it work with earlier versions actually prevents users that have yet to upgrade their editor from breaking if they decide to upgrade to the current version of NGO (whichever version that will be once this PR is merged). Otherwise, it would be considered a breaking change for earlier 6000.4 & 6000.5 versions.
But yeah... that is a good point and one of the reasons why I migrated all of the changes into the single
FindObjects.ByType<T>method... so there is one place that handles this which also reduces the number of times we have to use the conditional define.Test project had two places that I added this to in order to prevent from having to make
FindObjectspublic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also do the work to remove the scripting defines once we no longer support that Unity version. So these defines won't live forever