fix(scene): avoid scene ID collision on load

Do not serialize the SceneID component.
Generate a new SceneID when loading a scene file dynamically to prevent ID collisions.
Update related tests and scene graph builders.
This commit is contained in:
2026-05-10 22:50:05 +09:00
parent a95ff01366
commit 314b0111f0
14 changed files with 200 additions and 156 deletions

View File

@@ -117,16 +117,18 @@ public class SceneSerializationTests
Assert.AreEqual(3, data.Entities.Count, $"data contained {data.Entities.Count} entities");
foreach (var ent in data.Entities)
{
Assert.IsTrue(ent.Components.Count > 0, "Entity has no components");
}
Assert.IsTrue(ent.Components.Count >= 0, "Entity has no components"); // Can be 0 because we might have entities without components, but should not be negative
}
var loadResult = _serializationService.LoadSceneIntoEditorWorld(data);
Assert.IsTrue(loadResult.IsSuccess, loadResult.Message);
var world = _worldService.EditorWorld;
using var scope = AllocationManager.CreateStackScope();
scene = loadResult.Value;
using var scope = AllocationManager.CreateStackScope();
using var entities = SceneManager.GetSceneEntities(scene, world, scope.AllocationHandle);
Assert.AreEqual(3, entities.Count, $"Expected 3 entities for scene {scene.ID} but found {entities.Count}");
Assert.AreEqual(3, entities.Count, $"Expected 3 entities for scene {scene.id} but found {entities.Count}");
}
[TestMethod]
@@ -271,8 +273,7 @@ public class SceneSerializationTests
initialCount += chunk.EntityCount;
}
// EditorWorldService creates 1 default scene entity, plus 4 from this test = 5
Assert.AreEqual(5, initialCount, "Expected 5 entities (1 default + 4 from test).");
Assert.AreEqual(4, initialCount, "Expected 4 entities.");
var filePath = Path.Combine(_projectRoot, "SingleLoad.gscene");
_serializationService.SaveSceneFromEditorWorld(filePath, scene);