EcsRx / ecsrx

A reactive take on the ECS pattern for .net game developers
MIT License
520 stars 36 forks source link

Adding the same type of component twice fails silently #6

Closed JayPavlina closed 5 years ago

JayPavlina commented 5 years ago

I have not tried with AddComponent<T>(), but if you use entity.AddComponent(new WhateverComponent()) twice, it will not give an error, but it will only have one of the components.

grofit commented 5 years ago

As mentioned in chat behind the scenes it is always just overwriting the existing component when you add again, I am not entirely sure if this is correct behaviour or not as you would expect it to add not update/set.

I have added a set of exceptions that are only in debug builds that will throw an exception if you try to add an existing component, but at run time it may not be a problem. Let me know your thoughts on this.

JayPavlina commented 5 years ago

I think including an exception in debug builds but not in release builds is the correct behavior. What preprocessor directive are you using?

grofit commented 5 years ago

I am using #DEBUG which almost all platforms adhere to, I will mark this as closed but feel free to re-raise if you think there should be other changes. I am happy to discuss other options in more specific issues around adding other notions as atm there is just Add but maybe there should be Update or Set which is what is done under the hood.