diff --git a/Assets/Scripts/ServerShared/Entity.cs b/Assets/Scripts/ServerShared/Entity.cs index bf30ee927..bbca6a2ad 100644 --- a/Assets/Scripts/ServerShared/Entity.cs +++ b/Assets/Scripts/ServerShared/Entity.cs @@ -5,6 +5,7 @@ using GameCult.Caching; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using MessagePack; using UniRx; @@ -87,7 +88,9 @@ public abstract class Entity public readonly Dictionary Messages = new Dictionary(); private readonly Dictionary _visibilitySources = new Dictionary(); // A read-only view: the only writes are SetSignature and the decay loop in Update, both below. - public IReadOnlyDictionary VisibilitySources => _visibilitySources; + // A ReadOnlyDictionary over the private field, created once: a cast back to Dictionary fails. + private ReadOnlyDictionary _visibilityView; + public IReadOnlyDictionary VisibilitySources => _visibilityView ??= new ReadOnlyDictionary(_visibilitySources); // The one writer of VisibilitySources (the decay loop in Update is the one decayer). Every light signature // names its channel and the item that produced it (null for the hull).