Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com).
### Added

### Changed

### Removed

### Fixed

- Fixed: Hosting again after failing to host now works correctly
- Fixed endless dialog boxes when adding a NetworkBehaviour to a NetworkManager or vice-versa. (#1947)

## [1.0.0-pre.8] - 2022-04-27

Expand Down
33 changes: 33 additions & 0 deletions com.unity.netcode.gameobjects/Editor/NetworkBehaviourEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,39 @@ public static void CheckForNetworkObject(GameObject gameObject, bool networkObje

// Now get the root parent transform to the current GameObject (or itself)
var rootTransform = GetRootParentTransform(gameObject.transform);
var networkManager = rootTransform.GetComponent<NetworkManager>();
if (networkManager == null)
{
networkManager = rootTransform.GetComponentInChildren<NetworkManager>();
}

// If there is a NetworkManager, then notify the user that a NetworkManager cannot have NetworkBehaviour components
if (networkManager != null)
{
var networkBehaviours = networkManager.gameObject.GetComponents<NetworkBehaviour>();
var networkBehavioursChildren = networkManager.gameObject.GetComponentsInChildren<NetworkBehaviour>();
if (networkBehaviours.Length > 0 || networkBehavioursChildren.Length > 0)
{
if (EditorUtility.DisplayDialog("NetworkBehaviour or NetworkManager Cannot Be Added", $"{nameof(NetworkManager)}s cannot have {nameof(NetworkBehaviour)} components added to the root parent or any of its children." +
$" Would you like to remove the NetworkManager or NetworkBehaviour?", "NetworkManager", "NetworkBehaviour"))
{
DestroyImmediate(networkManager);
}
else
{
foreach (var networkBehaviour in networkBehaviours)
{
DestroyImmediate(networkBehaviour);
}

foreach (var networkBehaviour in networkBehaviours)
{
DestroyImmediate(networkBehaviour);
}
}
return;
}
}

// Otherwise, check to see if there is any NetworkObject from the root GameObject down to all children.
// If not, notify the user that NetworkBehaviours require that the relative GameObject has a NetworkObject component.
Expand Down