Git Product home page Git Product logo

Comments (4)

chrischu avatar chrischu commented on April 28, 2024

The thing about groups (at least as far as I know) they do not really respond to the entity being added/removed but to each individual component.

So in your PlayerSelectActionAttackSytem you replace the position of the entity, therefore triggering all the groups again. In effect the replace triggers the remove event first (since the old position is removed) and then the add event (since the new position is added).

I hope that makes things a little bit clearer and helps you solve the problem.

from entitas.

sschmid avatar sschmid commented on April 28, 2024

An entity is part of a group, when it fulfills the requirements of the matcher. In your case

Group group = pool.GetGroup(Matcher.AllOf(Matcher.PlayerSelectActionAttack, Matcher.Position));
onAdded = group.CreateObserver (GroupEventType.OnEntityAdded);
onRemoved = group.CreateObserver (GroupEventType.OnEntityRemoved);

an entity belongs to a group when it has a PlayerSelectActionAttackComponent and a PositionComponent.
Whenever you replace either of those it will be removed from the group (intentionally), because the idea is to remove the old component (=> entity doesn't match anymore) and the replace it with the new component (=> entity matches again). As a result e.ReplaceXyz will always trigger OnEntityAdded AND OnEntityRemoved

from entitas.

sschmid avatar sschmid commented on April 28, 2024

Btw, AttackPointerController looks like it should be a ReactiveSystem rather than a MonoBehaviour. A ReactiveSystem is using a GroupObserver under the hood, so you don't have to mess with it. If you still want to use GroupObservers don't forget to call observer.ClearCollectedEntities()
You can get the most out of Entitas if you try putting all your logic into dedicated systems doing only one thing.

from entitas.

jraselin avatar jraselin commented on April 28, 2024

Thanks for yours responses

Now, I understand the concept of ReplaceComponent

You can get the most out of Entitas if you try putting all your logic into dedicated systems doing only one thing.

Ok, I will remove all UI Logic and create dedicated systems

Regards

from entitas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.