Skip to content

fix: notify networkmanager and networkobject not allowed #1777

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

Conversation

NoelStephensUnity
Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity commented Mar 5, 2022

Adding a GameObject with a NetworkObject component as a child to the GameObject that is assigned the NetworkManager component will cause a soft synchronization error. It is advised to avoid assigning NetworkObjects to the parent GameObject with the NetworkManager component or to any child GameObject of the parent GameObject. This only applies to a GameObject with the NetworkManager component assigned to it.

Users should be notified of this while within the editor and should not allow them to proceed with any configuration as described above.
MTT-1598
MTT-1634

Changelog

com.unity.netcode.gameobjects

  • Fixed lack of notification that NetworkManager and NetworkObject cannot be added to the same GameObject with in-editor notifications

Testing and Documentation

  • No tests have been added (editor only update)

Notification Displayed:

image

NetworkObject Removed

image

notify the user when they try to add a NetworkObject to a GameObject that already has a NetworkManager assigned to it.
extending the INetworkManagerHelper interface.
Renamed the method being invoked to NotifyUserNetworkObjectRemoved in order to be more explicit in what was happening.
Updated comments
@NoelStephensUnity NoelStephensUnity changed the title Fix/notify networkmanager and networkobject not allowed fix: notify networkmanager and networkobject not allowed Mar 5, 2022
adding a test to validate that checking for a NetworkObject, removing the NetworkObject, and notifying the user that a NetworkManager cannot exist if a NetworkObject resides on the GameObject.  This also now checks children containing a NetworkObject.  It does not need to check for a parent as this is checked after to invoking NetworkManagerCheckForParent.
if (!EditorApplication.isUpdating)
{
Object.DestroyImmediate(networkObject);
var message = $"A {nameof(GameObject)} cannot have both a {nameof(NetworkManager)} and {nameof(NetworkObject)} assigned to it.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool, but what we don't tell users here is that you not only can't have a GO that has a NO and a NM, but you also cannot have children of a NM that have NOs. I would like the message to convey that, else people can have a setup that matches your error message but is still broken.

Bonus points if you flag the "children" scenario and then have a dedicated message for that one (vs. one catchall message)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't need to add additional code for the child checking. Just adjusted the language of the message.

var networkManager = gameObject.AddComponent<NetworkManager>();

// The error message we should expect
var messageToCheck = $"A {nameof(GameObject)} cannot have both a {nameof(NetworkManager)} and {nameof(NetworkObject)} assigned to it.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC we have banned the use of "checking for specific error messages", because it's so easy to forget that if you fix a message in one spot then the tests won't pass.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added method to return the error message.

making a method to return the error message.
adjusting the error message to include children in the description.
adding comments for clarity.
Adding a validation check to assure the NetworkObject has been removed.
@NoelStephensUnity NoelStephensUnity merged commit 5ea87e0 into develop Mar 8, 2022
@NoelStephensUnity NoelStephensUnity deleted the fix/notify-networkmanager-and-networkobject-not-allowed branch March 8, 2022 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants