Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
b9fe0d2
feat: Added support for client anticipation in NetworkVariables and N…
ShadauxCat Mar 27, 2024
0c70ae3
chore: add develop 2.0.0 to triggers and conventional pr (#2861)
NoelStephensUnity Apr 3, 2024
b097d74
fix: Fixed instability issues in the tests and optimized them so they…
ShadauxCat Apr 3, 2024
5dcc00c
Use slough artifactory in CI Part 2 (#2867)
HenrikPoulsen Apr 5, 2024
ac46fa7
fix: NetworkTransform synchronize position when half float precision …
NoelStephensUnity Apr 5, 2024
5b15609
chore: replicate PR-2833 physics2d rigidbody2d fix (#2871)
NoelStephensUnity Apr 5, 2024
3ca359d
chore: migrate PR-2812 remove animator requirement (#2872)
NoelStephensUnity Apr 5, 2024
d90292d
chore: migrate 2830 allow null references in NetworkBehaviourReferenc…
NoelStephensUnity Apr 5, 2024
d97d968
fix: Update API docs for MaxPayloadSize (#2877)
jabbacakes Apr 17, 2024
76e6cb0
chore: update code owners (#2889)
NoelStephensUnity Apr 18, 2024
b008929
fix: API doc fixes from user feedback (#2878)
jabbacakes Apr 25, 2024
e3643cf
chore: merge 1.9.1 into develop (#2899)
NoelStephensUnity Apr 25, 2024
cd6ead3
feat: add pre and post spawn methods (#2906)
NoelStephensUnity May 8, 2024
bcb891b
fix: NetworkRigidbody2D not changing body type with authority [MTT-85…
NoelStephensUnity May 9, 2024
f9c6731
fix: in-scene networkobject with networktransform synchronization whe…
NoelStephensUnity May 10, 2024
66d4134
fix: Fix for NullReferenceException during client Shutdown (#2921)
samlucas-unity May 10, 2024
2b38d55
fix: unreliable deltas half float synch jitter (#2922)
NoelStephensUnity May 14, 2024
1644801
fix: In-scene placed NetworkObjects getting destroyed if early discon…
NoelStephensUnity May 14, 2024
dc021c6
fix: client side disconnect incorrect client count on host-server sid…
NoelStephensUnity Jun 3, 2024
cd154af
chore: use xray for verifying package (#2944)
miniwolf Jun 5, 2024
7915bd4
fix: Added support for byte on NetworkVariable through codegen (#2953)
Ufabsther Jun 25, 2024
f0db817
fix: scenemanager clean up ScenesLoaded after synch unloading of rema…
NoelStephensUnity Jul 18, 2024
4400390
fix: Realtime Network Stats Monitor Not Displaying RPC Metrics in Rel…
NoelStephensUnity Jul 19, 2024
dbf6b03
chore: NGO 1.10.0 merge back to develop NGO develop (#2987)
fluong6 Jul 29, 2024
3863794
fix: Improve API doc for OnGainedOwnership and OnLostOwnership (#2996)
jabbacakes Aug 5, 2024
cb11580
fix: fixedstring byte writing and comparing (#2992)
NoelStephensUnity Aug 6, 2024
b2f5e84
fix: dual triggers generating false state transition [MTTB-48] (#2999)
NoelStephensUnity Aug 7, 2024
231b36d
fix: collections not detecting deltas backport to v1.x.x (#3005)
NoelStephensUnity Aug 13, 2024
beb08e8
fix: adding null checks when accessing NetworkBehaviour (#3011)
fluong6 Aug 19, 2024
142e757
chore: NGO 1.11.0 merge back to develop NGO develop (#3024)
fluong6 Aug 26, 2024
6d43f0a
fix: Stop checking hierarchy changed in playmode (#3027)
NoelStephensUnity Aug 26, 2024
ca23b3c
fix: unity collections 2-2-x support in 2022.3 with NGO v1.x.x (#3033)
NoelStephensUnity Aug 26, 2024
a597b9f
fix: prevent exception when showing despawned or destroyed NetworkObj…
NoelStephensUnity Aug 26, 2024
2fd4114
Local changes for addressable support
kroecks May 10, 2024
36625fa
pending update
kroecks May 10, 2024
8d7b51b
local trollking changes
kroecks May 10, 2024
640a7a3
minor change
kroecks Jun 8, 2024
4470a47
Update CODEOWNERS
NoelStephensUnity Sep 2, 2024
505261c
fix: allow the check for a NetworkObject component on NetworkBehaviou…
NoelStephensUnity Sep 3, 2024
2da5a98
chore: Upgrading unity-downloader-cli (#3048)
fluong6 Sep 6, 2024
f41fb30
fix: player prefab null exception when using prefabhash connection ap…
NoelStephensUnity Sep 6, 2024
67b27b7
fix: Add size validation to named and unnamed message sending (#3043)
larus Sep 6, 2024
39818f2
fix: exception thrown when rpc received for depsawned object (back-po…
NoelStephensUnity Sep 9, 2024
490fb93
fix: networkanimator only updates observers backport (#3058)
NoelStephensUnity Sep 11, 2024
8477fd4
fix: NetworkManager instantiate & destroy notifications and player sp…
NoelStephensUnity Oct 8, 2024
25ec4a5
fix: in-sceneobject NetworkObject update in editor tool (#3084)
NoelStephensUnity Oct 10, 2024
1532417
fix(editor): NetworkPrefabProcessor not marking prefab list dirty (#3…
mbaker3 Oct 17, 2024
264b30d
bump version to 2.1.1
fluong6 Oct 18, 2024
7f639ff
Merge branch 'Unity-Technologies:develop' into addressable
kroecks Oct 31, 2024
bebd5a5
Merge remote-tracking branch 'origin/2.1.1' into addressables
kroecks Oct 31, 2024
8e494c4
upgrade changes
kroecks Nov 6, 2024
b7ee6ef
update
NoelStephensUnity Dec 12, 2024
4a77fb2
update
NoelStephensUnity Dec 12, 2024
088755e
update
NoelStephensUnity Dec 12, 2024
004a220
fix
NoelStephensUnity Dec 12, 2024
64195d5
style
NoelStephensUnity Dec 12, 2024
1914d3c
style
NoelStephensUnity Dec 12, 2024
658ef01
style
NoelStephensUnity Dec 12, 2024
6de550b
chore: merge develop 2 0 0 updates with SessionOwner permissions (#3176)
NoelStephensUnity Dec 13, 2024
c0e65f4
fix
NoelStephensUnity Dec 16, 2024
ba49065
fix: server, host, or session owner not populating in-scene placed ob…
NoelStephensUnity Dec 16, 2024
a49e1b8
Merge branch 'two' into clean
kroecks Mar 9, 2025
aa6f559
fixes
kroecks Mar 9, 2025
5267b2b
update
NoelStephensUnity Apr 14, 2025
bc46537
update
NoelStephensUnity Apr 14, 2025
524918e
Merge remote-tracking branch 'unity/release/2.3.1' into clean2
kroecks Apr 19, 2025
73c3a18
Merge updates
kroecks Apr 19, 2025
00744cd
logging
kroecks Apr 19, 2025
07b9508
add log
kroecks Apr 19, 2025
e565739
minor change
kroecks Oct 5, 2025
20f9aee
Merge remote-tracking branch 'unity/develop-2.0.0' into clean2
kroecks Oct 5, 2025
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
8 changes: 8 additions & 0 deletions com.unity.netcode.gameobjects/Components.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ public ulong GetConfig(bool cache = true)
{
var sortedDictionary = Prefabs.NetworkPrefabOverrideLinks.OrderBy(x => x.Key);
foreach (var sortedEntry in sortedDictionary)

{
Debug.Log($"[NetworkConfig] - GetConfig - [{sortedEntry.Key}={sortedEntry.Value.Prefab}]");
writer.WriteValueSafe(sortedEntry.Key);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using TrollKing.Core;
using UnityEngine;

namespace Unity.Netcode
Expand All @@ -13,6 +14,8 @@ namespace Unity.Netcode
[Serializable]
public class NetworkPrefabs
{
private static readonly NetworkLogScope k_Log = new NetworkLogScope(nameof(NetworkPrefabs));

/// <summary>
/// Edit-time scripted object containing a list of NetworkPrefabs.
/// </summary>
Expand Down Expand Up @@ -52,6 +55,7 @@ public class NetworkPrefabs

private void AddTriggeredByNetworkPrefabList(NetworkPrefab networkPrefab)
{
k_Log.Debug(() => $"NetworkPrefabs AddTriggeredByNetworkPrefabList [networkPrefab={networkPrefab}]");
if (AddPrefabRegistration(networkPrefab))
{
// Don't add this to m_RuntimeAddedPrefabs
Expand All @@ -62,6 +66,7 @@ private void AddTriggeredByNetworkPrefabList(NetworkPrefab networkPrefab)

private void RemoveTriggeredByNetworkPrefabList(NetworkPrefab networkPrefab)
{
k_Log.Debug(() => $"NetworkPrefabs RemoveTriggeredByNetworkPrefabList [networkPrefab={networkPrefab}]");
m_Prefabs.Remove(networkPrefab);
}

Expand Down Expand Up @@ -93,6 +98,7 @@ internal void Shutdown()
/// <param name="warnInvalid">When true, logs warnings about invalid prefabs that are removed during initialization</param>
public void Initialize(bool warnInvalid = true)
{
k_Log.Debug(() => $"NetworkPrefabs Initialize [warnInvalid={warnInvalid}]");
m_Prefabs.Clear();
foreach (var list in NetworkPrefabsLists)
{
Expand All @@ -111,6 +117,8 @@ public void Initialize(bool warnInvalid = true)
{
foreach (var networkPrefab in list.PrefabList)
{
var netObj = networkPrefab.Prefab.GetComponent<NetworkObject>();
k_Log.Debug(() => $"NetworkPrefabs Add networkPrefab [networkPrefab={networkPrefab}] [prefab={networkPrefab.Prefab}] [prefabHash={netObj.PrefabIdHash}] [globalHash={netObj.GlobalObjectIdHash}]");
prefabs.Add(networkPrefab);
}
}
Expand Down Expand Up @@ -288,9 +296,19 @@ private bool AddPrefabRegistration(NetworkPrefab networkPrefab)
{
return false;
}

var netObj = networkPrefab.Prefab.GetComponent<NetworkObject>();
if (netObj)
{
k_Log.Debug(() => $"NetworkPrefabs AddPrefabRegistration [prefab={networkPrefab.Prefab.name}] [networkPrefab={networkPrefab}] [hash={netObj.PrefabIdHash}] [global={netObj.GlobalObjectIdHash}]");
}



// Safeguard validation check since this method is called from outside of NetworkConfig and we can't control what's passed in.
if (!networkPrefab.Validate())
{
Debug.LogError($"NetworkPrefabs AddPrefabRegistration INVALID [networkPrefab={networkPrefab}]");
return false;
}

Expand All @@ -303,14 +321,15 @@ private bool AddPrefabRegistration(NetworkPrefab networkPrefab)
var networkObject = networkPrefab.Prefab.GetComponent<NetworkObject>();

// This should never happen, but in the case it somehow does log an error and remove the duplicate entry
Debug.LogError($"{nameof(NetworkPrefab)} ({networkObject.name}) has a duplicate {nameof(NetworkObject.GlobalObjectIdHash)} source entry value of: {source}!");
Debug.LogError($"NetworkPrefabs {nameof(NetworkPrefab)} ({networkObject.name}) has a duplicate {nameof(NetworkObject.GlobalObjectIdHash)} source entry value of: {source}!");
return false;
}

// If we don't have an override configured, registration is simple!
if (networkPrefab.Override == NetworkPrefabOverride.None)
{
NetworkPrefabOverrideLinks.Add(source, networkPrefab);
k_Log.Debug(() => $"NetworkPrefabs AddPrefabRegistration NetworkPrefabOverrideLinks [prefab={networkPrefab.Prefab.name}] [source={source}] [networkPrefab={networkPrefab}]");
return true;
}

Expand Down
183 changes: 183 additions & 0 deletions com.unity.netcode.gameobjects/Runtime/Core/NetworkLogScope.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
using System;
using System.Collections.Generic;
using UnityEngine;

namespace TrollKing.Core
{
public enum NetworkLoggingLevel
{
Debug,
Info,
Warn,
Error,
Exception,
None
}

public class NetworkLogScope
{
private readonly string m_LoggerName;
private readonly NetworkLoggingLevel m_Level = NetworkLoggingLevel.Info;

public NetworkLogScope(string logName, NetworkLoggingLevel logLevel = NetworkLoggingLevel.Info)
{
m_LoggerName = logName;
m_Level = logLevel;
}

public NetworkLoggingLevel GetLevel()
{
return m_Level;
}

public void Log(Func<string> stringProvider, NetworkLoggingLevel logLevel = NetworkLoggingLevel.Info)
{
if (logLevel >= m_Level)
{
string logString = stringProvider.Invoke();
DateTime time = DateTime.Now;
var shortTime = time.ToString("T");

switch (logLevel)
{
case NetworkLoggingLevel.Debug:
UnityEngine.Debug.Log($"[{shortTime}][DEBUG][{m_LoggerName}] {logString}");
break;
case NetworkLoggingLevel.Info:
UnityEngine.Debug.Log($"[{shortTime}][INFO][{m_LoggerName}] {logString}");
break;
case NetworkLoggingLevel.Warn:
UnityEngine.Debug.LogWarning($"[{shortTime}][WARN][{m_LoggerName}] {logString}");
break;
case NetworkLoggingLevel.Error:
UnityEngine.Debug.LogError($"[{shortTime}][ERROR][{m_LoggerName}] {logString}");
break;
case NetworkLoggingLevel.Exception:
UnityEngine.Debug.LogError($"[{shortTime}][EXCEPTION][{m_LoggerName}] {logString}");
break;
default:
throw new ArgumentOutOfRangeException(nameof(logLevel), logLevel, null);
}
}
}

public void Debug(Func<string> logString)
{
Log(logString, NetworkLoggingLevel.Debug);
}

public void Info(Func<string> logString)
{
Log(logString, NetworkLoggingLevel.Info);
}

public void Warning(Func<string> logString)
{
Log(logString, NetworkLoggingLevel.Warn);
}

public void LogWarning(Func<string> logString)
{
Log(logString, NetworkLoggingLevel.Warn);
}

public void Error(Func<string> logString)
{
Log(logString, NetworkLoggingLevel.Error);
}

public void LogError(Func<string> logString)
{
Log(logString, NetworkLoggingLevel.Error);
}

public void LogException(Exception e)
{
UnityEngine.Debug.LogException(e);
}

public void LogError(Exception e)
{
UnityEngine.Debug.LogError($"[{m_LoggerName}] {e}");
UnityEngine.Debug.LogException(e);
}
}

public static class NetworkGameObjectUtility
{
private static readonly NetworkLogScope Log = new NetworkLogScope(nameof(NetworkGameObjectUtility));

private static string NetworkGetScenePathRecursive(Transform go, string path)
{
if (go.parent == null)
{
return $"{go.gameObject.scene.name}:{go.name}:{path}";
}

return NetworkGetScenePathRecursive(go.parent, $"{go.name}:{path}");
}

// Depth first, we are going all the way down each leg
public static void NetworkGetAllHierarchyChildrenRecursive(this GameObject source, ref Queue<GameObject> queue)
{
if (source == null)
{
return;
}

int children = source.transform.childCount;
for (int i = 0; i < children; i++)
{
var child = source.transform.GetChild(i);
var go = child.gameObject;
Log.Debug(() => $"AddingHierarchyChild {go}");
queue.Enqueue(go);
NetworkGetAllHierarchyChildrenRecursive(go, ref queue);
}
}

public static Queue<GameObject> NetworkGetAllHierarchyChildren(this GameObject root)
{
var retVal = new Queue<GameObject>();
if (root == null)
{
return retVal;
}
Log.Debug(() => $"AddingHierarchyParent {root}");
retVal.Enqueue(root);
root.NetworkGetAllHierarchyChildrenRecursive(ref retVal);
return retVal;
}

public static string NetworkGetScenePath(this GameObject go)
{
return NetworkGetScenePath(go.transform);
}

public static string NetworkGetScenePath(this Transform go)
{
return NetworkGetScenePathRecursive(go, "");
}

public static string NetworkGetSceneName(this GameObject go)
{
return go.scene.name;
}

public static bool NetworkTryGetComponentInParent<T>(this GameObject go, out T comp)
{
var parent = go.transform;
while (parent != null && parent.parent != parent)
{
if (parent.TryGetComponent(out comp))
{
return true;
}
parent = parent.parent;
}

comp = default;
return false;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ public int MaximumFragmentedMessageSize
get => MessageManager.FragmentedMessageMaxSize;
}

internal void Initialize(bool server)
public virtual void Initialize(bool server)
{
#if DEVELOPMENT_BUILD || UNITY_EDITOR
if (!DisableNotOptimizedSerializedType)
Expand Down
19 changes: 16 additions & 3 deletions com.unity.netcode.gameobjects/Runtime/Core/NetworkUpdateLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public enum NetworkUpdateStage : byte
PostScriptLateUpdate = 8,
/// <summary>
/// Updated after the Monobehaviour.LateUpdate for all components is invoked
/// and all rendering is complete
/// </summary>
PostLateUpdate = 7
}
Expand All @@ -74,12 +75,24 @@ public static class NetworkUpdateLoop
private static Dictionary<NetworkUpdateStage, INetworkUpdateSystem[]> s_UpdateSystem_Arrays;
private const int k_UpdateSystem_InitialArrayCapacity = 1024;

private static NetworkUpdateStage[] _CACHED_ENUM = null;

public static NetworkUpdateStage[] GetNetworkUpdateStageEnumValues()
{
if (_CACHED_ENUM == null)
{
_CACHED_ENUM = (NetworkUpdateStage[])Enum.GetValues(typeof(NetworkUpdateStage));
}

return _CACHED_ENUM;
}

static NetworkUpdateLoop()
{
s_UpdateSystem_Sets = new Dictionary<NetworkUpdateStage, HashSet<INetworkUpdateSystem>>();
s_UpdateSystem_Arrays = new Dictionary<NetworkUpdateStage, INetworkUpdateSystem[]>();

foreach (NetworkUpdateStage updateStage in Enum.GetValues(typeof(NetworkUpdateStage)))
foreach (NetworkUpdateStage updateStage in GetNetworkUpdateStageEnumValues())
{
s_UpdateSystem_Sets.Add(updateStage, new HashSet<INetworkUpdateSystem>());
s_UpdateSystem_Arrays.Add(updateStage, new INetworkUpdateSystem[k_UpdateSystem_InitialArrayCapacity]);
Expand All @@ -92,7 +105,7 @@ static NetworkUpdateLoop()
/// <param name="updateSystem">The <see cref="INetworkUpdateSystem"/> implementation to register for all network updates</param>
public static void RegisterAllNetworkUpdates(this INetworkUpdateSystem updateSystem)
{
foreach (NetworkUpdateStage updateStage in Enum.GetValues(typeof(NetworkUpdateStage)))
foreach (NetworkUpdateStage updateStage in GetNetworkUpdateStageEnumValues())
{
RegisterNetworkUpdate(updateSystem, updateStage);
}
Expand Down Expand Up @@ -136,7 +149,7 @@ public static void RegisterNetworkUpdate(this INetworkUpdateSystem updateSystem,
/// <param name="updateSystem">The <see cref="INetworkUpdateSystem"/> implementation to deregister from all network updates</param>
public static void UnregisterAllNetworkUpdates(this INetworkUpdateSystem updateSystem)
{
foreach (NetworkUpdateStage updateStage in Enum.GetValues(typeof(NetworkUpdateStage)))
foreach (NetworkUpdateStage updateStage in GetNetworkUpdateStageEnumValues())
{
UnregisterNetworkUpdate(updateSystem, updateStage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public bool Deserialize(FastBufferReader reader, ref NetworkContext context, int
{
if (NetworkLog.CurrentLogLevel <= LogLevel.Normal)
{
NetworkLog.LogWarning($"{nameof(NetworkConfig)} mismatch. The configuration between the server and client does not match");
NetworkLog.LogWarning($"{nameof(NetworkConfig)} mismatch. IncomingHash=[{ConfigHash}] OurHash=[{networkManager.NetworkConfig.GetConfig()}] The configuration between the server and client does not match");
}

networkManager.DisconnectClient(context.SenderId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public void Serialize(FastBufferWriter writer, int targetVersion)

var startingSize = writer.Length;
var networkVariable = NetworkBehaviour.NetworkVariableFields[i];

var shouldWrite = networkVariable.IsDirty() &&
networkVariable.CanClientRead(TargetClientId) &&
(networkManager.IsServer || networkVariable.CanClientWrite(networkManager.LocalClientId)) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,8 @@ public void RemoveAt(int index)
// check write permissions
if (!CanClientWrite(m_NetworkManager.LocalClientId))
{
throw new InvalidOperationException("Client is not allowed to write to this NetworkList");
LogWritePermissionError();
return;
}

var value = m_List[index];
Expand Down
Loading