Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
15 changes: 14 additions & 1 deletion com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,20 @@ internal NetworkBehaviour GetNetworkBehaviourAtOrderIndex(ushort index)
{
if (NetworkLog.CurrentLogLevel <= LogLevel.Error)
{
NetworkLog.LogError($"Behaviour index was out of bounds. Did you mess up the order of your {nameof(NetworkBehaviour)}s?");
NetworkLog.LogError($"{nameof(NetworkBehaviour)} index {index} was out of bounds for {name}. NetworkBehaviours must be the same, and in the same order, between server and client.");
}

if (NetworkLog.CurrentLogLevel <= LogLevel.Developer)
Comment thread
JesseOlmer marked this conversation as resolved.
{
var currentKnownChildren = new System.Text.StringBuilder();
currentKnownChildren.Append($"Known child {nameof(NetworkBehaviour)}s:");
for(int i = 0; i < ChildNetworkBehaviours.Count; i++)
{
var childNetworkBehaviour = ChildNetworkBehaviours[i];
currentKnownChildren.Append($" [{i}] {childNetworkBehaviour.__getTypeName()}");
currentKnownChildren.Append(i < ChildNetworkBehaviours.Count - 1 ? "," : ".");
}
NetworkLog.LogInfo(currentKnownChildren.ToString());
}

return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Text.RegularExpressions;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
Expand Down Expand Up @@ -31,19 +32,17 @@ public void NetworkManagerOverrideTest()
}

[Test]
public void GetBehaviourIndexNone()
[TestCase(0)]
[TestCase(1)]
[TestCase(2)]
public void GetBehaviourIndexNone(int index)
{
var gameObject = new GameObject(nameof(GetBehaviourIndexNone));
var networkObject = gameObject.AddComponent<NetworkObject>();

// TODO: Maybe not hardcode message?
LogAssert.Expect(LogType.Error, $"[Netcode] Behaviour index was out of bounds. Did you mess up the order of your {nameof(NetworkBehaviour)}s?");
LogAssert.Expect(LogType.Error, $"[Netcode] Behaviour index was out of bounds. Did you mess up the order of your {nameof(NetworkBehaviour)}s?");
LogAssert.Expect(LogType.Error, $"[Netcode] Behaviour index was out of bounds. Did you mess up the order of your {nameof(NetworkBehaviour)}s?");
LogAssert.Expect(LogType.Error, new Regex(".*out of bounds.*"));

Assert.That(networkObject.GetNetworkBehaviourAtOrderIndex(0), Is.Null);
Assert.That(networkObject.GetNetworkBehaviourAtOrderIndex(1), Is.Null);
Assert.That(networkObject.GetNetworkBehaviourAtOrderIndex(2), Is.Null);
Assert.That(networkObject.GetNetworkBehaviourAtOrderIndex((ushort)index), Is.Null);

// Cleanup
Object.DestroyImmediate(gameObject);
Expand All @@ -56,13 +55,10 @@ public void GetBehaviourIndexOne()
var networkObject = gameObject.AddComponent<NetworkObject>();
var networkBehaviour = gameObject.AddComponent<EmptyNetworkBehaviour>();

// TODO: Maybe not hardcode message?
LogAssert.Expect(LogType.Error, $"[Netcode] Behaviour index was out of bounds. Did you mess up the order of your {nameof(NetworkBehaviour)}s?");
LogAssert.Expect(LogType.Error, $"[Netcode] Behaviour index was out of bounds. Did you mess up the order of your {nameof(NetworkBehaviour)}s?");
LogAssert.Expect(LogType.Error, new Regex(".*out of bounds.*"));

Assert.That(networkObject.GetNetworkBehaviourAtOrderIndex(0), Is.EqualTo(networkBehaviour));
Assert.That(networkObject.GetNetworkBehaviourAtOrderIndex(1), Is.Null);
Assert.That(networkObject.GetNetworkBehaviourAtOrderIndex(2), Is.Null);

// Cleanup
Object.DestroyImmediate(gameObject);
Expand Down