diff --git a/Content.Client/GameObjects/Components/DoAfterComponent.cs b/Content.Client/GameObjects/Components/DoAfterComponent.cs
index 1b665d2a31..e751f5a996 100644
--- a/Content.Client/GameObjects/Components/DoAfterComponent.cs
+++ b/Content.Client/GameObjects/Components/DoAfterComponent.cs
@@ -3,8 +3,10 @@ using System;
using System.Collections.Generic;
using Content.Client.GameObjects.EntitySystems.DoAfter;
using Content.Shared.GameObjects.Components;
+using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
+using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
@@ -38,6 +40,18 @@ namespace Content.Client.GameObjects.Components
}
}
+ public override void HandleMessage(ComponentMessage message, IComponent? component)
+ {
+ base.HandleMessage(message, component);
+ switch (message)
+ {
+ case PlayerDetachedMsg _:
+ _doAfters.Clear();
+ CancelledDoAfters.Clear();
+ break;
+ }
+ }
+
///
/// Remove a DoAfter without showing a cancellation graphic.
///
diff --git a/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterGui.cs b/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterGui.cs
index 35ea070048..b46b359ff4 100644
--- a/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterGui.cs
+++ b/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterGui.cs
@@ -43,6 +43,25 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter
LayoutContainer.SetGrowVertical(this, LayoutContainer.GrowDirection.Begin);
}
+ ///
+ /// Called when the mind is detached from an entity
+ ///
+ /// Rather than just dispose of the Gui we'll just remove its child controls and re-use the control.
+ public void Detached()
+ {
+ foreach (var (_, control) in _doAfterControls)
+ {
+ control.Dispose();
+ }
+ _doAfterControls.Clear();
+ foreach (var (_, control) in _doAfterBars)
+ {
+ control.Dispose();
+ }
+ _doAfterBars.Clear();
+ _cancelledDoAfters.Clear();
+ }
+
///
/// Add the necessary control for a DoAfter progress bar.
///
diff --git a/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs b/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs
index 8ba59fde7f..8aed094c7f 100644
--- a/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs
+++ b/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs
@@ -57,7 +57,7 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter
{
_player = entity;
// Setup the GUI and pass the new data to it if applicable.
- Gui?.Dispose();
+ Gui?.Detached();
if (entity == null)
{