[UUM-137284] Fixing warnings of 6.4+ due to obsoleted APIs#750
[UUM-137284] Fixing warnings of 6.4+ due to obsoleted APIs#750
Conversation
There was a problem hiding this comment.
The review has identified several issues in ConvertToNestedPrefab.cs, including potential compilation errors on older Unity versions, null safety concerns, and performance implications of synchronous search operations. Summary of new findings:
- High Importance: Potential compilation errors related to
EntityId.ToULongusage andISearchListreturn types. - Medium Importance: Risk of
NullReferenceExceptionwhen resolving search results. - Low Importance: Use of synchronous search requests may impact Editor performance.
🤖 Helpful? 👍/👎
| #if UNITY_6000_5_OR_NEWER | ||
| var items = UnityEditor.Search.SearchService.GetItems(searchContext, SearchFlags.Synchronous); | ||
| #else | ||
| var items = UnityEditor.Search.SearchService.Request(searchContext, SearchFlags.Synchronous); | ||
| #endif |
There was a problem hiding this comment.
Using SearchFlags.Synchronous and creating a new SearchContext (line 283) inside this method can significantly impact performance and lead to UI freezes in the Editor, especially in large projects. If GetSceneReferences is called frequently (e.g., in a loop over many objects), consider reusing the SearchContext or using an asynchronous search request with a callback.
🤖 Helpful? 👍/👎
| #else | ||
| var items = UnityEditor.Search.SearchService.Request(searchContext, SearchFlags.Synchronous); | ||
| #endif | ||
| return items.ConvertAll(x => x.ToObject()); |
There was a problem hiding this comment.
Have you considered that x.ToObject() might return null if the search result cannot be resolved to a valid UnityEngine.Object (e.g., if the object was destroyed or is in an unloaded scene)? To improve robustness, you might want to filter out these null values before returning the list to avoid potential NullReferenceExceptions in the caller. For example:
return items.Select(x => x.ToObject()).Where(obj => obj != null).ToList();🤖 Helpful? 👍/👎
Typo: The function calls were interverted (Request was called in the #else path so for 6.4 and under) What stems: ConvertAll is not available in ISearchList (that Request returns)
Purpose of this PR
Ticket/Jira #: UUM-137284
Fixing 2 warnings:
``(...)\com.unity.formats.fbx\com.unity.formats.fbx\Editor\ConvertToNestedPrefab.cs(277,30): warning CS0618: 'EntityId.GetRawData()' is obsolete: 'Please use EntityId.ToULong(EntityId) instead.'```
``(...)\com.unity.formats.fbx\com.unity.formats.fbx\Editor\ConvertToNestedPrefab.cs(286,29): warning CS0618: 'SearchService.GetItems(SearchContext, SearchFlags)' is obsolete: 'GetItems is deprecated, please use Request instead. GetItems will be removed in a future version.'````
Testing
Functional Testing status:
Performance Testing status:
Documentation & UX Writing
Additional information
Note to reviewers:
Reminder: