File tree 1 file changed +24
-6
lines changed
1 file changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -163,17 +163,35 @@ private void OnFootPrintInit(Entity<FootPrintComponent> ent, ref ComponentInit a
163
163
/// </summary>
164
164
private void OnFootPrintRemove ( Entity < FootPrintComponent > ent , ref ComponentRemove args )
165
165
{
166
- if ( ! TryGetTilePos ( ent . Owner , out var tilePos ) )
167
- return ;
166
+ // Try to get tile pos if entity is still valid
167
+ Vector2i ? tilePos = null ;
168
+ if ( ! Deleted ( ent ) && ! EntityManager . IsQueuedForDeletion ( ent ) && Transform ( ent ) . ParentUid . IsValid ( ) )
169
+ {
170
+ TryGetTilePos ( ent . Owner , out var pos ) ;
171
+ tilePos = pos ;
172
+ }
173
+
174
+ // If we couldn't get tile pos, search all tiles to find and remove this footprint
175
+ if ( tilePos == null )
176
+ {
177
+ foreach ( var ( pos , prints ) in _footprintsPerTile )
178
+ {
179
+ if ( ! prints . Contains ( ent . Owner ) )
180
+ continue ;
181
+
182
+ tilePos = pos ;
183
+ break ;
184
+ }
185
+ }
168
186
169
- if ( _footprintsPerTile . TryGetValue ( tilePos , out var footprints ) )
187
+ // Clean up the footprint tracking if we found it
188
+ if ( tilePos . HasValue && _footprintsPerTile . TryGetValue ( tilePos . Value , out var footprints ) )
170
189
{
171
- // Create a new queue without the removed footprint
172
190
var newQueue = new Queue < EntityUid > ( footprints . Where ( x => x != ent . Owner ) ) ;
173
191
if ( newQueue . Count > 0 )
174
- _footprintsPerTile [ tilePos ] = newQueue ;
192
+ _footprintsPerTile [ tilePos . Value ] = newQueue ;
175
193
else
176
- _footprintsPerTile . Remove ( tilePos ) ;
194
+ _footprintsPerTile . Remove ( tilePos . Value ) ;
177
195
}
178
196
}
179
197
You can’t perform that action at this time.
0 commit comments