How do I test if a IBufferElementData exists?

Hello. I am launching a humble foundation towards my space mmo today using DOTS/ECS, thank you all for the past year of help. I have one possibly final question. I’m adding this to an entity, but I am not sure how to check if it may already exist: DynamicBuffer dyn = em.AddBuffer(e);

By testing if it already exists, I can see if there is data I need to preserve, and not overwrite it.

Thanks again for a wonderful year of help. There’s a lot of hate on the internet lately, but the spirit of helping has never stopped as long as I’ve been on it since 1994. I was told it goes further back from the boss at the lab. He says he was there when some of the big guys weren’t big and silicon valley first started up. Everyone wanted to help and share info.

I’m not sure my title is exactly what I am asking…

I just want to make sure when I do line:

DynamicBuffer dyn = em.AddBuffer(e);

Whatever buffer I’m adding does not already exist because I’d retrieve it…

PSEUDO

DynamicBuffer dyn;
if (em.HasBuffer(e))
dyn=em.GetBuffer(e);
else
dyn=em.AddBuffer(e);

For a job, get a handle with GetBufferFromEntity outside and then test with HasComponent(Entity) on the handle.
I think on mainThread, EntityManager.HasComponent also works.

For a chunk there’s a Has method.

Maybe then matters are complicated because I’m looking for a pseudo return of an entity premtively looking forward in an EntityCommandBuffer:

Entity e = spawnCommandBufferQ(index, pos, vel, acc, q3, ecb, parallel_Position, e2);

if (World.DefaultGameObjectInjectionWorld.EntityManager.HasComponent(e))//line not happy
{}

Error spew:

ArgumentException: All entities created using EntityCommandBuffer.CreateEntity must be realized via playback(). One of the entities is still deferred (Index: -1).
Unity.Entities.EntityComponentStore.ValidateEntity (Unity.Entities.Entity entity) (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/EntityComponentStoreDebug.cs:210)
Unity.Entities.EntityComponentStore.Exists (Unity.Entities.Entity entity) (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/EntityComponentStore.cs:801)
Unity.Entities.EntityComponentStore.HasComponent (Unity.Entities.Entity entity, Unity.Entities.ComponentType type) (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/EntityComponentStore.cs:854)
Unity.Entities.EntityDataAccess.HasComponent (Unity.Entities.Entity entity, Unity.Entities.ComponentType type) (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/EntityDataAccess.cs:1056)
Unity.Entities.EntityManager.HasComponent[T] (Unity.Entities.Entity entity) (at Library/PackageCache/com.unity.entities@0.50.0-preview.24/Unity.Entities/EntityManager.cs:2852)
gff.spawnCommandBufferQplus (ItemDropBufferElement item, System.Int32 index, UnityEngine.Vector3 pos, UnityEngine.Vector3 vel, UnityEngine.Vector3 acc, Unity.Mathematics.quaternion q3, Unity.Entities.EntityCommandBuffer+ParallelWriter ecb, System.Int32 parallel_Position, Unity.Entities.Entity e2) (at Assets/Scripts/DOTS/gff.cs:367)

If that buffer is part of the prefab, check if the prefab has it instead. Otherwise you need to keep track of whether or not you added the buffer to the entity yourself. ECB doesn’t really keep track of archetype changes.

Yah, I think I just try and get too eloquent in my code. DOTS/ECS is more about functionality until the edge cases are sanded down… I can’t expect it to read the EntityComponents I attached to a GameObject until the devs have time putting that superfulous thing in… before the core mold is set, you never want to fix the outlier branches.

ty, I know what is going on