friflo / Friflo.Engine.ECS

C# ECS 🔥 high-performance
https://friflo.gitbook.io/friflo.engine.ecs
GNU Lesser General Public License v3.0
158 stars 11 forks source link

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

Closed dvdking closed 6 days ago

dvdking commented 3 months 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 3 months 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!

sergiyha commented 3 weeks ago

Hi. Any news about supporting Indexed Components using CommandBuffers and EntityBatch ?

friflo commented 6 days ago

Fixed in 3.0.0-preview.14.

Implemented also all other cases adding / removing / changing indexed components. Those cases are listed in my initial answer.