Skip to content

Commit fecd845

Browse files
Update & Fix
Some comments and minor adjustments. Fixing issue where the auto-sort was disabled when using inspector view.
1 parent 3be0719 commit fecd845

4 files changed

Lines changed: 22 additions & 12 deletions

File tree

com.unity.netcode.gameobjects/Runtime/Components/Helpers/NetworkObjectBridge.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#if UNIFIED_NETCODE
22
using Unity.NetCode;
3+
using UnityEditor;
34

45
namespace Unity.Netcode
56
{
@@ -13,14 +14,14 @@ namespace Unity.Netcode
1314
public partial class NetworkObjectBridge : GhostBehaviour
1415
{
1516

16-
#if UNITY_EDITOR && !UNITY_INCLUDE_TESTS
17+
#if UNITY_EDITOR
1718
[UnityEngine.HideInInspector]
1819
[UnityEngine.SerializeField]
1920
private bool m_Sorted = false;
2021
private void OnValidate()
2122
{
2223
// Sort only once when we have first been added.
23-
if (!m_Sorted)
24+
if (!m_Sorted && !EditorApplication.isPlaying)
2425
{
2526
while (UnityEditorInternal.ComponentUtility.MoveComponentUp(this))
2627
{

com.unity.netcode.gameobjects/Runtime/Components/Helpers/UnifiedUpdateConnections.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ protected override void OnUpdate()
3737
{
3838
var isServer = World.IsServer();
3939
var commandBuffer = new EntityCommandBuffer(Allocator.Temp);
40-
// var networkManager = NetworkManager.Singleton;
41-
foreach (var networkManager in GameObject.FindObjectsByType<NetworkManager>())
40+
foreach (var networkManager in Object.FindObjectsByType<NetworkManager>())
4241
{
43-
foreach (var (networkId, connectionState, entity) in SystemAPI.Query<NetworkId, ConnectionState>()
44-
.WithNone<NetworkStreamConnection>().WithEntityAccess())
42+
foreach (var (networkId, connectionState, entity) in SystemAPI.Query<NetworkId, ConnectionState>().WithNone<NetworkStreamConnection>().WithEntityAccess())
4543
{
4644
commandBuffer.RemoveComponent<ConnectionState>(entity);
4745
m_TempConnections.Add(new NetcodeConnection
48-
{ World = World, Entity = entity, NetworkId = networkId.Value });
46+
{
47+
World = World,
48+
Entity = entity,
49+
NetworkId = networkId.Value
50+
});
4951
}
5052

5153
foreach (var con in m_TempConnections)
@@ -62,7 +64,7 @@ protected override void OnUpdate()
6264
if (!m_NewConnections.ContainsKey(networkId.Value))
6365
{
6466
var newConnection = new NetcodeConnection
65-
{ World = World, Entity = entity, NetworkId = networkId.Value };
67+
{ World = World, Entity = entity, NetworkId = networkId.Value };
6668
m_NewConnections.Add(networkId.Value, newConnection);
6769
}
6870
}
@@ -101,11 +103,10 @@ protected override void OnUpdate()
101103
{
102104
commandBuffer.RemoveComponent<ConnectionState>(entity);
103105
NetworkManager.OnNetCodeDisconnect?.Invoke(new NetcodeConnection
104-
{ World = World, Entity = entity, NetworkId = networkId.Value });
106+
{ World = World, Entity = entity, NetworkId = networkId.Value });
105107
}
106108
}
107109
}
108-
109110
commandBuffer.Playback(EntityManager);
110111
}
111112

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,6 +1841,8 @@ internal void ShutdownInternal()
18411841
{
18421842
// Dispose of all worlds
18431843
World.DisposeAllWorlds();
1844+
// Clear the world assigned from previous session
1845+
NetcodeWorld = null;
18441846
}
18451847
catch (Exception ex)
18461848
{

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2793,6 +2793,7 @@ internal string GenerateDisabledNetworkBehaviourWarning(NetworkBehaviour network
27932793
}
27942794

27952795
internal Dictionary<ushort, NetworkBehaviour> ChildNetworkBehaviours;
2796+
27962797
internal bool InitializeChildNetworkBehaviours()
27972798
{
27982799
ChildNetworkBehaviours = new Dictionary<ushort, NetworkBehaviour>();
@@ -2839,6 +2840,7 @@ internal bool InitializeChildNetworkBehaviours()
28392840
// automatically removed later).
28402841
if (HasGhost)
28412842
{
2843+
28422844
if (NetworkRigidbodies != null)
28432845
{
28442846
for (int i = NetworkRigidbodies.Count - 1; i >= 0; i--)
@@ -2849,10 +2851,14 @@ internal bool InitializeChildNetworkBehaviours()
28492851
NetworkRigidbodies.Clear();
28502852
}
28512853

2852-
// TODO: We might want to make this whole thing a noop as opposed to completely
2853-
// removing it.
2854+
// When hybrid spawning, the transform is synchronized by the GhostObject.
2855+
// As a convenience, we remove and destroy all NetworkTransforms.
2856+
// TODO-Parenting-Related-Area: We need to replicate this functionality in a GhostAdapter
2857+
// Possibly use a "Synchronize" property and display only on children of a root parent GhostAdapter.
28542858
if (NetworkTransforms != null)
28552859
{
2860+
NetworkManager.Log.Warning(new Logging.Context(LogLevel.Developer, $"[]{name} Hybrid spawned objects do not support {nameof(NetworkTransform)} and " +
2861+
$"are removed at runtime. If hybrid spawning is intended, then remove it from the network prefab to avoid allocating and de-allocating at runtime."));
28562862
for (int i = NetworkTransforms.Count - 1; i >= 0; i--)
28572863
{
28582864
ChildNetworkBehaviours.Remove(NetworkTransforms[i].NetworkBehaviourId);

0 commit comments

Comments
 (0)