sschmid / Entitas

Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
MIT License
7.16k stars 1.11k forks source link

collector's bug #915

Closed 1115803755 closed 2 years ago

1115803755 commented 5 years ago

Hi,

I have found a bug want to contribute.

Here's some code

public void Activate() { for (int i = 0; i < _groups.Length; i++) { var group = _groups[i]; var groupEvent = _groupEvents[i]; switch (groupEvent) { case GroupEvent.Added: group.OnEntityAdded -= _addEntityCache; group.OnEntityAdded += _addEntityCache; break; case GroupEvent.Removed: group.OnEntityRemoved -= _addEntityCache; group.OnEntityRemoved += _addEntityCache; break; case GroupEvent.AddedOrRemoved: group.OnEntityAdded -= _addEntityCache; group.OnEntityAdded += _addEntityCache; group.OnEntityRemoved -= _addEntityCache; group.OnEntityRemoved += _addEntityCache; break; } } }

As you can see, "group.OnEntityRemoved += _addEntityCache;" is add wrong EventHandle

c0ffeeartc commented 5 years ago

Collector caches entities on Added/Removed/AddedOrRemoved, it looks as intended.

1115803755 commented 5 years ago

I mean why did group.OnEntityRemoved and group.OnEntityAdded add the same EventCache

c0ffeeartc commented 5 years ago

I mean why did group.OnEntityRemoved and group.OnEntityAdded add the same EventCache

group.OnEntityRemoved and group.OnEntityAdded can add to the same HashSet. Based on how Collector was set up.

1115803755 commented 5 years ago

Think you, I got it wrong.