Component manipulations

In OOP we used to pass components by reference, and we had access to gameObjects from those. Now we deal with structures, and it does not make sense to pass the whole ComponentData structure without even being able to get Entity of the Component. Instead, we would pass Entities around as some sort of pointers. While using this approach, I found it kind of too verbose to check if the required Component is attached to the Entity before getting it. Is something like EntityManager.TryGetValue(entity, out component) planned? Also, RemoveComponent returns void rather than bool, which would force additional HasComponent check in some cases.

Up

You can write extension methods for the EntityManager class for such handling, if these methods will not be added in the short future.

1 Like

I would also love to have those in EntityCommandBuffer where I could not use HasComponent at the barrier execution time. Sometimes the component was there when I issue command and so I use SetComponentData, later but before barrier execution someone removed it. In this case it would be an error as the correct command should be AddComponentData.

1 Like

Maybe a upsert approach ? EntityCommandBuffer.SetOrAddComponentData();