Entity.Set performs no checks if components exists at all to be able to set it, even in debug mode.
emelrad12 opened this issue · 2 comments
Calling Entity.Set to set a component that doesn't exist on a said entity, causes directly memory corruption.
A suggestion would be to make it safe, but add a non safe version for performance.
As the vast majority of ecs code normally would not be affected by such change in performance just a small part of it, that is called very often, hence I would suggest making the default behavior safe.
In our game we have a method called Ensure(Entity) where it checks Has first which might be useful, so anyone that knows for sure the component exists can use Set or otherwise use the other method.
I think it would be particularly good to add more documentation on the unsafe methods on their assumptions. If trying to Set a component to an entity that lacks it will break it that should be documented. The worst ones are the ones that don't immediately crash, like Add for a component on an entity that already has it.