Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
## [Unreleased]

### Added
- Added test to ensure a warning occurs when nesting NetworkObjects in a NetworkPrefab

- Added `NetworkManager.RemoveNetworkPrefab(...)` to remove a prefab from the prefabs list (#1950)
Comment thread
TwoTenPvP marked this conversation as resolved.
Outdated

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public Func<ConnectionApprovalRequest, ConnectionApprovalResponse> ConnectionApp
internal static event Action OnSingletonReady;

#if UNITY_EDITOR
private void OnValidate()
internal void OnValidate()
{
if (NetworkConfig == null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using NUnit.Framework;
using UnityEngine;
using Unity.Netcode.Editor;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools;

namespace Unity.Netcode.EditorTests
Expand Down Expand Up @@ -78,5 +80,37 @@ public void NetworkObjectNotAllowed([Values] NetworkObjectPlacement networkObjec
// Clean up
Object.DestroyImmediate(gameObject);
}

[Test]
public void NestedNetworkObjectPrefabCheck()
{
// Setup
var networkManagerObject = new GameObject(nameof(NestedNetworkObjectPrefabCheck));
var networkManager = networkManagerObject.AddComponent<NetworkManager>();
networkManager.NetworkConfig = new NetworkConfig();

var parent = new GameObject("Parent").AddComponent<NetworkObject>();
var child = new GameObject("Child").AddComponent<NetworkObject>();

// Set parent
child.transform.SetParent(parent.transform);

// Make it a prefab, warning only applies to prefabs
networkManager.AddNetworkPrefab(parent.gameObject);

// Mark scene as dirty to ensure OnValidate actually runs
EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());

// Force OnValidate
networkManager.OnValidate();

// Expect a warning
LogAssert.Expect(LogType.Warning, $"[Netcode] {NetworkManager.PrefabDebugHelper(networkManager.NetworkConfig.NetworkPrefabs[0])} has child {nameof(NetworkObject)}(s) but they will not be spawned across the network (unsupported {nameof(NetworkPrefab)} setup)");

// Clean up
Object.DestroyImmediate(networkManagerObject);
Object.DestroyImmediate(parent);

}
}
}