Why don't add "Update/Replace" GroupEvent?
See original GitHub issueHi,
It’s me again, I have a question want to ask. In game reactive system, we have to override the GetTrigger method to collect game entity while some components added or removed, but I cannot see the “Update/Replace” event.
I checked the source code, in Group.cs, there is some code holding the updating event:
/// This is used by the context to manage the group.
public void UpdateEntity(TEntity entity, int index, IComponent previousComponent, IComponent newComponent) {
if (_entities.Contains(entity)) {
if (OnEntityRemoved != null) {
OnEntityRemoved(this, entity, index, previousComponent);
}
if (OnEntityAdded != null) {
OnEntityAdded(this, entity, index, newComponent);
}
if (OnEntityUpdated != null) {
OnEntityUpdated(
this, entity, index, previousComponent, newComponent
);
}
}
}
But, in Collector.cs where the OnEntityAdded and OnEntityRemoved delegate were assigned, there’s not any code to set Update/Replace:
/// Activates the Collector and will start collecting
/// changed entities. Collectors are activated by default.
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;
}
}
}
And there is not “Update/Replace” in GroupEvent.cs at all.
So, Is there some design reason or another reason to stop adding “Update/Replace” event in Collector?
Cheers
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
CRUD: When to use Create, Replace, Update or Delete in ...
For major changes like migrations to new servers, I would use Replace, since update is much weaker (albeit not as weak as Create)....
Read more >Group Policy Drive Map Win10 issue
Action: Replace, Reconnect checked, Remove item when no longer applied, ... Update will create a drive map if none exist and will update...
Read more >Update calendar invite without sending 'meeting has been ...
Someone at my company asked if it was possible to update a calendar invite without spamming all the attendees that the meeting invitation ......
Read more >Insert into a MySQL table or update if exists
REPLACE works exactly like INSERT , except that if an old row in the table has the same value as a new row...
Read more >[GA4] Modify and create events in Analytics
Modifying an event overwrites an existing event by adding, changing, or removing parameters. Modified events are processed before created events are processed. ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@FNGgames I understand your meaning now, that’s to say, I can write CheckDoSomethingStatusSystem like this:
and then, if some systems call
I will collect these entity and process by this system. Thanks for your explanation, so patient.
I just want to ask another un-resolved problem again, why in Entitas source code Group.cs, there is
OnEntityUpdatedto handle replace event only, but haven’t realized it and remain a never used variables, it makes me confused.And more, a method calling
ReplaceDoSomethingStatusmay raise two different events:Addedif hasn’t any Component before orRemovedandAddedif has one.Maybe, if you design it one relates one:
AddDoSomethingStatusjust raisesAddedeventRemoveDoSomethingStatusjust raisesRemovedeventReplaceDoSomethingStatusjust raisesReplacedevent if it has already one, if you haven’t one, it raisesAddedevent.Is it a better design? Please don’t mind, I just make a suggestion.
@IDNoise thanks for your help, do you mean, you open a issue before, but @sschmid haven’t modified? And he suggests us do:
rather than:
Perhaps in the filter make sure you state that entity does not have the component so then when the system is triggered it’ll only execute when the entity does not have the component which would be similar to reacting on remove but with replace. Or just actually use the component generated remove method and then just use the add method. I’ve even ran into sometimes where although using replace is just faster to do using removed and then add was just better for my system filtering