From 5b746af01d65a9d62f8996753bd3a2967664d6f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Thu, 15 Oct 2026 08:06:29 +0300 Subject: [PATCH] Fix SetParent not unlinking from the old parent --- Game.Server/BaseEntity.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Game.Server/BaseEntity.cs b/Game.Server/BaseEntity.cs index 3f04bb11..956dca97 100644 --- a/Game.Server/BaseEntity.cs +++ b/Game.Server/BaseEntity.cs @@ -1261,9 +1261,21 @@ public void SetParent(BaseEntity? parentEntity, int attachment = -1) { if (attachment == -1) attachment = ParentAttachment; + if (!IsPlayer() && Game.Client.GarrysMod.GarrysMod.IsSacredEntity(Classname ?? "")) { + Warning($"Refusing to set parent on {Classname}!\n"); + return; + } + + for (BaseEntity? ancestor = parentEntity; ancestor != null; ancestor = ancestor.GetParent()) { + if (ancestor.GetParent() == this) + ancestor.SetParent(null); + } + bool wasNotParented = GetParent() == null; BaseEntity? oldParent = GetParent(); + UnlinkFromParent(this); + Parent.Set(parentEntity); if (parentEntity == this) {