-
Notifications
You must be signed in to change notification settings - Fork 87
Fix obsolete warning when using instance ID in probuilder #643
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
base: master
Are you sure you want to change the base?
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
🤖 Helpful? Please react with 👍/👎 | Questions❓Please reach out in Slack #ask-u-pr-agent |
PR Code Suggestions ✨Explore these optional code suggestions:
🤖 Helpful? Please react with 👍/👎 | Questions❓Please reach out in Slack #ask-u-pr-agent |
|||||||||
Codecov ReportAttention: Patch coverage is
@@ Coverage Diff @@
## master #643 +/- ##
==========================================
- Coverage 35.57% 35.57% -0.01%
==========================================
Files 277 277
Lines 34892 34898 +6
==========================================
+ Hits 12413 12415 +2
- Misses 22479 22483 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
| switch (kind) | ||
| { | ||
| case ObjectChangeKind.CreateGameObjectHierarchy: | ||
| { | ||
| stream.GetCreateGameObjectHierarchyEvent(index, out var data); | ||
| return UnityEditor.EditorUtility.EntityIdToObject(data.entityId) as GameObject; | ||
| } | ||
| case ObjectChangeKind.ChangeGameObjectStructure: | ||
| { | ||
| stream.GetChangeGameObjectStructureEvent(index, out var data); | ||
| return UnityEditor.EditorUtility.EntityIdToObject(data.entityId) as GameObject; | ||
| } | ||
| case ObjectChangeKind.ChangeGameObjectStructureHierarchy: |
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.
Hmm it feels a bit of shame that we're checking again for the ObjectChangeKind here when that was already done in ObjectEventChangesPublished(). Instead of passing the stream, index and kind as params, couldn't you just pass the data itself? And have the variants of stream.Get[bla bla]Event() be called in the if checks inside ObjectEventChangesPublished()?
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 considered extracting the event data inside the main loop to avoid the double switch. However, because the data structs (CreateGameObjectHierarchyEventArgs) have different property names in Unity 6000.4 (entityId vs instanceId), doing so would require peppering the main loop with #if UNITY_6000_4_OR_NEWER blocks for every single event type to access the correct ID field.
I chose to encapsulate the switch and the #if logic inside GetGameObjectFromEvent. It does check the kind twice, but it keeps the main logic loop readable and free of preprocessor directives. I felt readability outweighed the negligible cost of the extra switch statement here.
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.
But does the type of data itself differ? Or is it still CreateGameObjectHierarchyEventArgs in both cases? Because if that type doesn't change, can't you just do:
private static GameObject GetGameObjectFromEvent(CreateGameObjectHierarchyEventArgs data)
{
#if UNITY_6000_4_OR_NEWER
return UnityEditor.EditorUtility.EntityIdToObject(data.entityId) as GameObject;
#else
var instanceId = data.instanceId
#pragma warning disable CS0618 // Type or member is obsolete
return UnityEditor.EditorUtility.InstanceIDToObject(instanceId) as GameObject;
#pragma warning restore CS0618
#endif
}
Although now that I think about it, I guess each event has a different args type... BUT if all these args types share a common parent/interface that has the entityId/instanceId than I think this would be a more concise approach?
Co-authored-by: jmcduff-unity <87323996+jmcduff-unity@users.noreply.github.com>
DO NOT FORGET TO INCLUDE A CHANGELOG ENTRY
Purpose of this PR
Warning appear when opening probuilder projects. This was fixed by adding entityId instead of instanceID. to make sure old project worked as well, we used #IF UNITY_6000_4_Or_NEWWER
Links
https://jira.unity3d.com/browse/PBLD-284
Comments to Reviewers
N/A