diff --git a/Assets/Mirror/Core/NetworkIdentity.cs b/Assets/Mirror/Core/NetworkIdentity.cs index 18428ee9e..ddbdb8065 100644 --- a/Assets/Mirror/Core/NetworkIdentity.cs +++ b/Assets/Mirror/Core/NetworkIdentity.cs @@ -32,6 +32,9 @@ public enum Visibility { Default, ForceHidden, ForceShown } [HelpURL("https://mirror-networking.gitbook.io/docs/components/network-identity")] public sealed class NetworkIdentity : MonoBehaviour { + [Tooltip("Performance optimization for passive objects like Npcs, ItemDrops, Trees, Structures etc. skip broadcasting.\nPassive objects only spawn and despawn, their state isn't synced.\nThis can make a huge performance difference for large worlds with lots of passive objects.")] + public bool passive = false; + /// Returns true if running as a client and this object was spawned by a server. // // IMPORTANT: diff --git a/Assets/Mirror/Core/NetworkServer.cs b/Assets/Mirror/Core/NetworkServer.cs index b46f2d572..1a755accb 100644 --- a/Assets/Mirror/Core/NetworkServer.cs +++ b/Assets/Mirror/Core/NetworkServer.cs @@ -1657,6 +1657,9 @@ static void BroadcastIdentity( NetworkWriterPooled ownerWriter, NetworkWriterPooled observersWriter) { + // skip passive identities for performance + if (identity.passive) return; + // only serialize if it has any observers // TODO only set dirty if has observers? would be easiest. if (identity.observers.Count > 0) diff --git a/Assets/Mirror/Examples/BenchmarkIdle/Npc.cs b/Assets/Mirror/Examples/BenchmarkIdle/Npc.cs index 7c9bd8d5f..7658c5a47 100644 --- a/Assets/Mirror/Examples/BenchmarkIdle/Npc.cs +++ b/Assets/Mirror/Examples/BenchmarkIdle/Npc.cs @@ -26,13 +26,16 @@ public override void OnStartServer() // color coding // can't do this in update, it's too expensive rend.material.color = sleeping ? sleepingColor : activeColor; + + // set passive + netIdentity.passive = sleeping; } [ServerCallback] void Update() { - // set dirty if not sleeping. - // only counts as dirty every 'syncInterval'. + // set dirty every 'syncInterval'. + // passive identities will ignore it. if (!sleeping) ++value; } }