Skip to content

Commit 5bba965

Browse files
committed
Small fixes
1 parent f571af2 commit 5bba965

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,6 +2854,10 @@ internal static void VerifyParentingStatus()
28542854
/// </returns>
28552855
public ushort GetNetworkBehaviourOrderIndex(NetworkBehaviour instance)
28562856
{
2857+
if (ChildNetworkBehaviours == null)
2858+
{
2859+
InitializeChildNetworkBehaviours();
2860+
}
28572861
return instance.NetworkBehaviourId;
28582862
}
28592863

@@ -2864,6 +2868,11 @@ public ushort GetNetworkBehaviourOrderIndex(NetworkBehaviour instance)
28642868
/// <returns>The <see cref="NetworkBehaviour"/> at the ordered index value or null if it does not exist.</returns>
28652869
public NetworkBehaviour GetNetworkBehaviourAtOrderIndex(ushort index)
28662870
{
2871+
if (ChildNetworkBehaviours == null)
2872+
{
2873+
InitializeChildNetworkBehaviours();
2874+
}
2875+
28672876
if (ChildNetworkBehaviours.TryGetValue(index, out var childBehaviour))
28682877
{
28692878
return childBehaviour;
@@ -3533,8 +3542,6 @@ internal void SceneChangedUpdate(Scene scene, bool notify = false)
35333542

35343543
private void Awake()
35353544
{
3536-
InitializeChildNetworkBehaviours();
3537-
35383545
SetCachedParent(transform.parent);
35393546
SceneOrigin = gameObject.scene;
35403547
}

com.unity.netcode.gameobjects/Tests/Editor/NetworkObjectTests.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,14 @@ public void NetworkManagerOverrideTest()
3333
}
3434

3535
[Test]
36-
[TestCase(0)]
37-
[TestCase(1)]
38-
[TestCase(2)]
39-
public void GetBehaviourIndexNone(int index)
36+
public void GetBehaviourIndexNone()
4037
{
4138
var gameObject = new GameObject(nameof(GetBehaviourIndexNone));
4239
var networkObject = gameObject.AddComponent<NetworkObject>();
4340

4441
LogAssert.Expect(LogType.Error, new Regex(".*out of bounds.*"));
4542

46-
Assert.That(networkObject.GetNetworkBehaviourAtOrderIndex((ushort)index), Is.Null);
43+
Assert.That(networkObject.GetNetworkBehaviourAtOrderIndex(5), Is.Null);
4744

4845
// Cleanup
4946
Object.DestroyImmediate(gameObject);

com.unity.netcode.gameobjects/Tests/Runtime/TestHelpers/NetcodeIntegrationTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,6 +2650,11 @@ public static void SimulateOneFrame()
26502650
{
26512651
var method = obj.GetType().GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
26522652
method?.Invoke(obj, new object[] { });
2653+
if (obj.ChildNetworkBehaviours == null)
2654+
{
2655+
obj.InitializeChildNetworkBehaviours();
2656+
}
2657+
26532658
foreach (var behaviour in obj.ChildNetworkBehaviours)
26542659
{
26552660
var behaviourMethod = behaviour.GetType().GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

0 commit comments

Comments
 (0)