Coder Social home page Coder Social logo

Comments (10)

sschmid avatar sschmid commented on May 1, 2024

Automatic Entity Reference Counting (AERC) was introduced to fix an internal bug (#25). It works automatically and ist managed by Entitas. Usually you don't have contact with this feature and you should never manually call entity.Retain() or entity.Release(). The only exception to call these methods manually is when you want to keep a reference to an entity on your own, which is not recommended.
Basically you can happily forget, that this feature even exists ;)

from entitas.

YimingIsCOLD avatar YimingIsCOLD commented on May 1, 2024

Thank you for your explanation. At first, I didn't know that the order of creating the system will affect how the loop goes. So I do not need to worry about having a lot of retained entities?

from entitas.

JuDelCo avatar JuDelCo commented on May 1, 2024

Try disabling systems at runtime to see which one is retaining the entities. Anyway... how much is a lot ?

from entitas.

sschmid avatar sschmid commented on May 1, 2024

@hahasss95 I don't really understand what you mean. Could you explain what your concerns are? Again, consider AERC as an internal feature, you don't really have to care. It's all managed automatically for you.

from entitas.

YimingIsCOLD avatar YimingIsCOLD commented on May 1, 2024

I managed to have no retained entities as before that there were as much as around 50. I was afraid that it will slow down my game as there were no reusable entities as all the destroyed entities are being retained.

from entitas.

sschmid avatar sschmid commented on May 1, 2024

Sorry, I have the feeling I still don't understand what the question is.

...there were as much as around 50

did you debug your game, or how do you know the retained entities count? Because there is no public access to this information.

... as all the destroyed entities are being retained.

pool.DestroyEntity() will release entities and therefore make them reusable.

To answer your initial question

Is retained entities bad? Is there anyway to clear the retained entities or move it to reusable entities?

It's all managed for you automatically, you don't have to do anything. You don't even have to know that entities are being reused under the hood as this is just an performance and memory optimization. Call pool.CreateEntity() if you need one, call pool.DestroyEntity() if you want to destroy it ;) That's basically it. Anything else are implementation details.

I was afraid that it will slow down my game...

AERC won't slow your game down ;)

Hope that helps.

from entitas.

YimingIsCOLD avatar YimingIsCOLD commented on May 1, 2024

Yeah I did debug my game to see the number of retained entities. Okay thank you. I will just let how the entities work and not change things that I do not know. Thanks for all the explanations! :)

from entitas.

sschmid avatar sschmid commented on May 1, 2024

I mean, if you experience some unexpected behaviour or you think you found a bug, let me know. The expected behaviour is:
When you create a new entity

  • _reusableEntities.Count == 0
  • _retainedEntities.Count == 0

When you destroy this entity

  • _reusableEntities.Count == 1
  • _retainedEntities.Count == 0

Depending on your reactive systems and group observers _retainedEntities.Count can be > 0, but will be == 0 by the end of the loop.

from entitas.

sschmid avatar sschmid commented on May 1, 2024

I think I know what you mean now! :)
I could reproduce what you explained. The problem was that the GroupObserver could potentially retain entities multiple times. I fixed that in release 0.22.2

Let me know if it fixes your issue as well.
Thanks :)

from entitas.

YimingIsCOLD avatar YimingIsCOLD commented on May 1, 2024

Yeah, It seems to work fine now. No more retained entities.

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.