File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -136,8 +136,8 @@ public bool isSpawned
136
136
/// <summary>
137
137
/// The current clients observing the object
138
138
/// </summary>
139
- public HashSet < uint > observers = new HashSet < uint > ( ) ;
140
- private HashSet < uint > previousObservers = new HashSet < uint > ( ) ;
139
+ public readonly HashSet < uint > observers = new HashSet < uint > ( ) ;
140
+ private readonly HashSet < uint > previousObservers = new HashSet < uint > ( ) ;
141
141
142
142
internal void RebuildObservers ( uint ? clientId = null )
143
143
{
@@ -162,7 +162,6 @@ internal void RebuildObservers(uint? clientId = null)
162
162
previousObservers . Clear ( ) ;
163
163
foreach ( var item in observers )
164
164
previousObservers . Add ( item ) ;
165
- observers . Clear ( ) ;
166
165
bool update = false ;
167
166
for ( int i = 0 ; i < childNetworkedBehaviours . Count ; i ++ )
168
167
{
@@ -199,6 +198,7 @@ internal void RebuildObservers(uint? clientId = null)
199
198
foreach ( var item in previousObservers )
200
199
observers . Add ( item ) ;
201
200
}
201
+ previousObservers . Clear ( ) ;
202
202
}
203
203
}
204
204
Original file line number Diff line number Diff line change @@ -86,6 +86,13 @@ public override bool OnCheckObserver(uint newClientId)
86
86
/// <returns>Wheter or not we changed anything</returns>
87
87
public override bool OnRebuildObservers ( HashSet < uint > observers )
88
88
{
89
+ // This implementation is an example.
90
+ // Not efficient. We remove all old observers as the API doesn't clear them for us.
91
+ // The reason it's not cleared is so that you don't have to iterate over your things if you simply
92
+ // Have an event driven system where you want to remove a player. Ex if they leave a zone
93
+ observers . Clear ( ) ;
94
+ observers = new HashSet < uint > ( ) ;
95
+
89
96
if ( ForceHidden )
90
97
{
91
98
// ensure player can still see themself
You can’t perform that action at this time.
0 commit comments