friflo / Friflo.Engine.ECS

High performance 🔥 C# ECS
https://friflo.gitbook.io/friflo.engine.ecs
GNU Lesser General Public License v3.0
110 stars 7 forks source link

Indexed component not found when adding component through EntityStore.CreateEntity #5

Open dvdking opened 1 month ago

dvdking commented 1 month ago

This test fails

    [Test]
    public static void Test_Index_ValueStructIndex()
    {
        var store   = new EntityStore();
        store.CreateEntity(new IndexedInt { value = 123 });

        var result = store.GetEntitiesWithComponentValue<IndexedInt, int>(123);
        AreEqual(1, result.Count);
    }

This does not fail

        var store   = new EntityStore();
        var entity1 = store.CreateEntity();
        entity1.AddComponent(new IndexedInt { value = 123 });
        var result = store.GetEntitiesWithComponentValue<IndexedInt, int>(123);
        AreEqual(1, result.Count);

batches fail too

        var store   = new EntityStore();
        var entity1 = store.CreateEntity();

        entity1.Batch().Add(new IndexedInt { value = 123 }).Apply();
        var result = store.GetEntitiesWithComponentValue<IndexedInt, int>(123);
        AreEqual(1, result.Count);
friflo commented 1 month ago

hey @dvdking

somebody tries this crazy stuff 👍🏼. This is currently a known issue for all new Component Types.

That is the reason why these new types are only available in 3.0.0-preview releases. Right now: AddComponent<>() and RemoveComponent<>() must be used.

I have to make adjustments in all extension methods in EntityExtensions and EntityStoreExtensions used in your first test.

Same for EntityBatch and CreateEntityBatch methods used in your last test. Without your post I guess I would have missed those two for the final release.

Also the CommandBuffer needs adjustments.

thx for feedback!