Load grid error related changes (#10817)

This commit is contained in:
Leon Friedrich
2022-08-26 01:33:40 +12:00
committed by GitHub
parent 561c527657
commit c65d1c51ce
11 changed files with 37 additions and 16 deletions

View File

@@ -80,8 +80,11 @@ public sealed class MindSystem : EntitySystem
}
else if (mind.GhostOnShutdown)
{
// Changing an entities parents while deleting is VERY sus. This WILL throw exceptions.
// TODO: just find the applicable spawn position dirctly without actually updating the transform's parent.
Transform(uid).AttachToGridOrMap();
var spawnPosition = Transform(uid).Coordinates;
// Use a regular timer here because the entity has probably been deleted.
Timer.Spawn(0, () =>
{
@@ -96,6 +99,13 @@ public sealed class MindSystem : EntitySystem
spawnPosition = _gameTicker.GetObserverSpawnPoint();
}
// TODO refactor observer spawning.
if (!spawnPosition.IsValid(EntityManager))
{
Logger.ErrorS("mind", $"Entity \"{ToPrettyString(uid)}\" for {mind.Mind?.CharacterName} was deleted, and no applicable spawn location is available.");
return;
}
var ghost = Spawn("MobObserver", spawnPosition);
var ghostComponent = Comp<GhostComponent>(ghost);
_ghostSystem.SetCanReturnToBody(ghostComponent, false);