Skip to content

Commit

Permalink
ECS - set EntityData.Id for deleted entities
Browse files Browse the repository at this point in the history
  • Loading branch information
friflo committed Aug 1, 2024
1 parent a0676f7 commit 02e1c79
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ECS/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
} }

/// <summary>Returns the <see cref="ECS.EntityName"/> reference of an entity.</summary>
Expand Down
4 changes: 4 additions & 0 deletions src/ECS/Entity/EntityData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,9 @@ internal EntityData(in EntityNode node, int id) {
Id = id;
compIndex = node.compIndex;
}

internal EntityData(int id) {
Id = id;
}
#endregion
}
5 changes: 4 additions & 1 deletion src/Tests/ECS/Entity/Test_EntityData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NullReferenceException>(() => {
GetTags(entity);
});
Expand Down

0 comments on commit 02e1c79

Please sign in to comment.