From 02e1c79f32e5edb67a30acab3cdcb933c7b75cee Mon Sep 17 00:00:00 2001 From: Ullrich Praetz Date: Thu, 1 Aug 2024 08:09:02 +0200 Subject: [PATCH] ECS - set EntityData.Id for deleted entities --- src/ECS/Entity.cs | 2 +- src/ECS/Entity/EntityData.cs | 4 ++++ src/Tests/ECS/Entity/Test_EntityData.cs | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ECS/Entity.cs b/src/ECS/Entity.cs index b1bb51dc..c5456560 100644 --- a/src/ECS/Entity.cs +++ b/src/ECS/Entity.cs @@ -259,7 +259,7 @@ public ref readonly Tags Tags { get { if (node.archetype != null && Revision == node.revision) { return new EntityData(node, Id); } - return default; + return new EntityData(Id); } } /// Returns the reference of an entity. diff --git a/src/ECS/Entity/EntityData.cs b/src/ECS/Entity/EntityData.cs index 28514402..1e86746a 100644 --- a/src/ECS/Entity/EntityData.cs +++ b/src/ECS/Entity/EntityData.cs @@ -85,5 +85,9 @@ internal EntityData(in EntityNode node, int id) { Id = id; compIndex = node.compIndex; } + + internal EntityData(int id) { + Id = id; + } #endregion } \ No newline at end of file diff --git a/src/Tests/ECS/Entity/Test_EntityData.cs b/src/Tests/ECS/Entity/Test_EntityData.cs index f20ee2e2..21821cf5 100644 --- a/src/Tests/ECS/Entity/Test_EntityData.cs +++ b/src/Tests/ECS/Entity/Test_EntityData.cs @@ -54,7 +54,10 @@ public static void Test_EntityData_access() entity.DeleteEntity(); data = entity.Data; - IsTrue(data.IsNull); + IsTrue ( data.IsNull); + AreEqual(1, data.Id); + AreEqual("Id: 1", data.ToString()); + Throws(() => { GetTags(entity); });