Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity.Detach() method doesn't invoke EntityChanged until next Update of EntityManager #723

Closed
SjaakAlvarez opened this issue Feb 8, 2021 · 1 comment
Assignees
Labels
Milestone

Comments

@SjaakAlvarez
Copy link
Contributor

When calling Detach() to remove a component, the entity is not updated until the next Update of the EntityManager.

For example:

When I Detach a component in a EntityProcessingSystem, the component bit is still set in the next EntityDrawSystem Update and the entity is still part of the ActiveEntities which might crash the code.

A quick and dirty solution is to modify EntityManager.OnComponentsChanged to:

private void OnComponentsChanged(int entityId)
{
    _changedEntities.Add(entityId);
    _entityToComponentBits[entityId] = _componentManager.CreateComponentBits(entityId);
    EntityChanged?.Invoke(entityId);
}
SjaakAlvarez added a commit to SjaakAlvarez/MonoGame.Extended that referenced this issue Feb 8, 2021
lithiumtoast pushed a commit that referenced this issue Mar 3, 2021
Entity.Detach() method doesn't invoke EntityChanged until next Update of EntityManager #723
@AristurtleDev AristurtleDev added this to the v4.0.0 milestone May 20, 2024
@AristurtleDev AristurtleDev self-assigned this Jun 1, 2024
@AristurtleDev
Copy link
Member

This was resolved in #724

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

2 participants