-
Notifications
You must be signed in to change notification settings - Fork 450
fix: Adds a null check for NetworkObjectReference => GameObject conversion [NCCBUG-172] #2158
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
fix: Adds a null check for NetworkObjectReference => GameObject conversion [NCCBUG-172] #2158
Conversation
…rsion [NCCBUG-172]
@@ -139,7 +139,7 @@ public override int GetHashCode() | |||
/// </summary> | |||
/// <param name="networkObjectRef">The <see cref="NetworkObjectReference"/> to convert from.</param> | |||
/// <returns>This returns the <see cref="GameObject"/> that the <see cref="NetworkObject"/> is attached to and is referenced by the <see cref="NetworkObjectReference"/> passed in as a parameter</returns> | |||
public static implicit operator GameObject(NetworkObjectReference networkObjectRef) => Resolve(networkObjectRef).gameObject; | |||
public static implicit operator GameObject(NetworkObjectReference networkObjectRef) => Resolve(networkObjectRef)?.gameObject; |
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.
Don't use null-conditional operator on MonoBehaviour's - it's not supported. You have to do the full if (ref != null)
and the engine marshalls to native to verify the object hasn't been destroyed.
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.
Changed. Thanks for pointing that out.
com.unity.netcode.gameobjects/Tests/Runtime/Serialization/NetworkObjectReferenceTests.cs
Outdated
Show resolved
Hide resolved
com.unity.netcode.gameobjects/Tests/Runtime/Serialization/NetworkObjectReferenceTests.cs
Outdated
Show resolved
Hide resolved
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.
null conditional issue definitely needs to be fixed. The test stuff is a suggestion but not required for my sign-off
…orkObjectReferenceTests.cs Co-authored-by: Jesse Olmer <jesseo@unity3d.com>
…_GameObject_conversion
…_GameObject_conversion
…rsion [NCCBUG-172] (Unity-Technologies#2158) * fix: Adds a null check for NetworkObjectReference => GameObject conversion [NCCBUG-172] * Changelog * style * Update com.unity.netcode.gameobjects/Tests/Runtime/Serialization/NetworkObjectReferenceTests.cs Co-authored-by: Jesse Olmer <jesseo@unity3d.com> * Review feedback. Co-authored-by: Jesse Olmer <jesseo@unity3d.com>
Changelog
Testing and Documentation