Skip to content

Commit c15498c

Browse files
update
cleaning up some of the POC adjustments. wrapping some debug within loglevel developer.
1 parent aa6ea10 commit c15498c

3 files changed

Lines changed: 30 additions & 96 deletions

File tree

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

Lines changed: 16 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2865,10 +2865,6 @@ internal struct SceneObject
28652865
public ulong OwnerClientId;
28662866
public ushort OwnershipFlags;
28672867

2868-
#if UNIFIED_NETCODE
2869-
public int GhostId;
2870-
#endif
2871-
28722868
public bool IsPlayerObject
28732869
{
28742870
get => ByteUtility.GetBit(m_BitField, 0);
@@ -3041,13 +3037,6 @@ public void Serialize(FastBufferWriter writer)
30413037
writer.WriteValue(OwnerObject.GetSceneOriginHandle());
30423038
}
30433039

3044-
#if UNIFIED_NETCODE
3045-
if (HasGhost)
3046-
{
3047-
writer.WriteValueSafe(GhostId);
3048-
}
3049-
#endif
3050-
30513040
// write placeholder for serialized data size.
30523041
// Can't be bitpacked because we don't know the value until we calculate it later
30533042
var positionBeforeSynchronizing = writer.Position;
@@ -3127,13 +3116,6 @@ public void Deserialize(FastBufferReader reader)
31273116
// scene handle that the NetworkObject resides in.
31283117
reader.ReadValue(out NetworkSceneHandle);
31293118

3130-
#if UNIFIED_NETCODE
3131-
if (HasGhost)
3132-
{
3133-
reader.ReadValueSafe(out GhostId);
3134-
}
3135-
#endif
3136-
31373119
// Read the size of the remaining synchronization data
31383120
// This data will be read in AddSceneObject()
31393121
reader.ReadValueSafe(out SynchronizationDataSize);
@@ -3233,7 +3215,6 @@ internal SceneObject GetMessageSceneObject(ulong targetClientId = NetworkManager
32333215
HasInstantiationData = InstantiationData != null && InstantiationData.Length > 0,
32343216
#if UNIFIED_NETCODE
32353217
HasGhost = HasGhost,
3236-
GhostId = HasGhost ? GhostInstance.ghostId : 0,
32373218
#endif
32383219
};
32393220

@@ -3553,15 +3534,15 @@ private void Awake()
35533534

35543535
}
35553536

3556-
private void OnEnable()
3557-
{
3558-
Debug.Log("Enabled!");
3559-
}
3537+
//private void OnEnable()
3538+
//{
3539+
// Debug.Log("Enabled!");
3540+
//}
35603541

3561-
private void OnDisable()
3562-
{
3563-
Debug.Log("Disabled!");
3564-
}
3542+
//private void OnDisable()
3543+
//{
3544+
// Debug.Log("Disabled!");
3545+
//}
35653546

35663547
#if UNIFIED_NETCODE
35673548

@@ -3580,87 +3561,31 @@ private void InitGhost()
35803561
// All instances with Ghosts are automatically registered
35813562
if (HasGhost && NetworkObjectBridge)
35823563
{
3583-
Debug.Log($"[{nameof(NetworkObject)}] GhostBridge {name} detected and instantiated.");
3564+
if (NetworkManager.LogLevel == LogLevel.Developer)
3565+
{
3566+
Debug.Log($"[{nameof(NetworkObject)}] GhostBridge {name} detected and instantiated.");
3567+
}
35843568
NetworkObjectBridge.NetworkObjectIdChanged += OnNetworkObjectIdChanged;
35853569
if (NetworkObjectBridge.NetworkObjectId.Value != 0)
35863570
{
35873571
RegisterGhostBridge();
35883572
}
3589-
//var networkObjectRegistration = (false, (ulong)0);
3590-
//NetworkManager.SpawnManager.RegisterGhostPendingSpawn(this, NetworkObjectBridge.NetworkObjectId);
3591-
//try
3592-
//{
3593-
// networkObjectRegistration = GhostAdapter.GetNetworkObjectId();
3594-
//}
3595-
//catch (Exception ex)
3596-
//{
3597-
// Debug.LogException(ex);
3598-
//}
3599-
3600-
//if (networkObjectRegistration.Item1)
3601-
//{
3602-
// // Authority and Non-Authority:
3603-
// // Upon instantiation it will always register itself as a Ghost that is pending NGO spawn.
3604-
3605-
// // Non-Authority:
3606-
// // - If registered prior to the CreateObjectMessage, then upon receiving the CreateObjectMessag it will be processed immediately using this instance.
3607-
// // - If registered after receiving the CreateObjectMessage, then upon registering it will also process any deferred CreateObjectMessages
3608-
// // If this happens prior to receiving the is received,
3609-
// // Authority:
3610-
// // Upon spawning locally, this entry is removed from the ghost pending spawn table.
3611-
3612-
3613-
3614-
//}
3615-
//else if (!NetworkManager.IsServer)
3616-
//{
3617-
// StartCoroutine(WaitForGhostData());
3618-
//}
3619-
//else
3620-
//{
3621-
// Debug.LogError($"[{name}] Failed to get ghost instance or GhostId is zero!");
3622-
//}
36233573
}
36243574
}
36253575

36263576
private void RegisterGhostBridge()
36273577
{
3628-
Debug.Log($"[{nameof(NetworkObject)}][{nameof(NetworkObjectId)}] NetworkObjectBridge notified instance exists with assigned ID of: {NetworkObjectBridge.NetworkObjectId.Value}");
3578+
if (NetworkManager.LogLevel == LogLevel.Developer)
3579+
{
3580+
Debug.Log($"[{nameof(NetworkObject)}][{nameof(NetworkObjectId)}] NetworkObjectBridge notified instance exists with assigned ID of: {NetworkObjectBridge.NetworkObjectId.Value}");
3581+
}
36293582
NetworkManager.SpawnManager.RegisterGhostPendingSpawn(this, NetworkObjectBridge.NetworkObjectId.Value);
36303583
}
36313584

36323585
private void OnNetworkObjectIdChanged(ulong networkObjectId)
36333586
{
36343587
RegisterGhostBridge();
36353588
}
3636-
3637-
//private System.Collections.IEnumerator WaitForGhostData()
3638-
//{
3639-
// var waitPeriod = new WaitForSeconds(0.1f);
3640-
// var timeout = Time.realtimeSinceStartup + 5.0f;
3641-
// while (timeout > Time.realtimeSinceStartup)
3642-
// {
3643-
// enabled = true;
3644-
// var networkObjectRegistration = (false, (ulong)0);
3645-
// try
3646-
// {
3647-
// networkObjectRegistration = GhostAdapter.GetNetworkObjectId();
3648-
// }
3649-
// catch (Exception ex)
3650-
// {
3651-
// Debug.LogException(ex);
3652-
// }
3653-
// if (networkObjectRegistration.Item1)
3654-
// {
3655-
// NetworkManager.SpawnManager.RegisterGhostPendingSpawn(this, networkObjectRegistration.Item2);
3656-
// yield break;
3657-
// }
3658-
// yield return waitPeriod;
3659-
// }
3660-
3661-
// Debug.Log("Timed out waiting for Ghost to be registered!");
3662-
3663-
//}
36643589
#endif
36653590

36663591
/// <summary>

com.unity.netcode.gameobjects/Runtime/Messaging/Messages/CreateObjectMessage.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,19 @@ public bool Deserialize(FastBufferReader reader, ref NetworkContext context, int
121121
}
122122

123123
#if UNIFIED_NETCODE
124-
UnityEngine.Debug.Log($"Received {nameof(CreateObjectMessage)} for NetworkObjectId-{ObjectInfo.NetworkObjectId}.");
124+
if (networkManager.LogLevel == LogLevel.Developer)
125+
{
126+
UnityEngine.Debug.Log($"Received {nameof(CreateObjectMessage)} for NetworkObjectId-{ObjectInfo.NetworkObjectId}.");
127+
}
128+
125129
// For now, we will defer the create object message until the associated Ghost is spawned
126130
if (ObjectInfo.HasGhost && !networkManager.SpawnManager.GhostsPendingSpawn.ContainsKey(ObjectInfo.NetworkObjectId))
127131
{
128-
UnityEngine.Debug.Log($"Deferring {nameof(CreateObjectMessage)} to wait for Ghost.");
129-
networkManager.DeferredMessageManager.DeferMessage(IDeferredNetworkMessageManager.TriggerType.OnGhostSpawned, (ulong)ObjectInfo.GhostId, reader, ref context, k_Name);
132+
if (networkManager.LogLevel == LogLevel.Developer)
133+
{
134+
UnityEngine.Debug.Log($"Deferring {nameof(CreateObjectMessage)} to wait for Ghost.");
135+
}
136+
networkManager.DeferredMessageManager.DeferMessage(IDeferredNetworkMessageManager.TriggerType.OnGhostSpawned, ObjectInfo.NetworkObjectId, reader, ref context, k_Name);
130137
return false;
131138
}
132139
#endif

com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ public class NetworkSpawnManager
3636

3737
public void RegisterGhostPendingSpawn(NetworkObject networkObject, ulong networkObjectId)
3838
{
39-
Debug.Log($"[{nameof(RegisterGhostPendingSpawn)}] Registering {networkObject.name} with a {nameof(NetworkObject.NetworkObjectId)} of {networkObjectId}.");
39+
if (NetworkManager.LogLevel == LogLevel.Developer)
40+
{
41+
Debug.Log($"[{nameof(RegisterGhostPendingSpawn)}] Registering {networkObject.name} with a {nameof(NetworkObject.NetworkObjectId)} of {networkObjectId}.");
42+
}
4043
GhostsPendingSpawn.TryAdd(networkObjectId, networkObject);
4144
NetworkManager.DeferredMessageManager.ProcessTriggers(IDeferredNetworkMessageManager.TriggerType.OnGhostSpawned, (ulong)networkObject.GhostInstance.ghostId);
4245
}
@@ -1138,7 +1141,6 @@ internal void AuthorityLocalSpawn([NotNull] NetworkObject networkObject, ulong n
11381141
if (networkObject.HasGhost)
11391142
{
11401143
networkObject.NetworkObjectBridge.NetworkObjectId.Value = networkObject.NetworkObjectId;
1141-
//networkObject.GhostAdapter.RegisterNetworkObjectId(networkObject.NetworkObjectId);
11421144
}
11431145
#endif
11441146

0 commit comments

Comments
 (0)