Skip to content

Commit f46eab5

Browse files
authored
Merge pull request #104 from kurobon-jp/feature/fix_delete_entity
Fix bug where scripts were not properly deleted
2 parents 5e00a0c + 58b03ae commit f46eab5

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/ECS/Entity/Store/Extension.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ private void RemoveEntityScript(int id)
105105
for (int n = 1; n <= len; n++) {
106106
if (scripts[n].id != id) continue;
107107
for (; n < len; n++) {
108-
scripts[n] = scripts[n + 1];
108+
var script = scripts[n + 1];
109+
scripts[n] = script;
110+
scriptMap[script.id] = n;
109111
}
110112
entityScriptCount = len;
111113
scripts[len] = default;

src/Tests/ECS/Entity/Test_Script.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,21 @@ public static void Test_3_Simulate_Editor() {
369369
test.Start();
370370
test.Update();
371371
}
372+
373+
[Test]
374+
public static void Test_DeleteEntity()
375+
{
376+
var store = new EntityStore(PidType.RandomPids);
377+
var entity1 = store.CreateEntity();
378+
var entity2 = store.CreateEntity();
379+
380+
entity1.AddScript(new TestScript1());
381+
entity2.AddScript(new TestScript1());
382+
383+
entity1.DeleteEntity();
384+
385+
AreEqual("id: 2 [*TestScript1]", entity2.ToString());
386+
}
372387
}
373388

374389
}

0 commit comments

Comments
 (0)