Search Unity

Keep getting a crash from entity archetype cache exceeding the 16MB limit

Discussion in 'Entity Component System' started by BigRookGames, Apr 20, 2021.

  1. BigRookGames

    BigRookGames

    Joined:
    Nov 24, 2014
    Posts:
    330
    around 11,000 archetypes. I thought that I read a long time ago it was going to be increased. Is there any way to increase this limit or release the cached archetypes? I know that it is defined in EntityComponentStore.cs at:
    Code (CSharp):
    1.  entities->m_ArchetypeChunkAllocator = new BlockAllocator(AllocatorManager.Persistent, 16 * 1024 * 1024); // 16MB should be enough
    which was from this thread: https://forum.unity.com/threads/ent...rchetype-count-with-repo.890815/#post-5903975

    @s_schoener mentions changing that piece of code to accommodate a higher cache limit, but it is managed code so I don't think I can change it.

    Right now I have what is essentially an enemy state system defined by tags and ecs systems where the entity will enter and leave states such as attack or retreat by adding and removing a component tag. There are quick a few flags I use with the pathfinding behaviors in there and considering every single flag would likely double the archetype count the number raises very quickly.

    Of course, I could rewrite the system to not add and remove components for the use of flags but to rather assign component data to define the states. I just found it very easy to keep all the systems orderly by having one per state, though I'm not sure if it moves the data each time it changes archetype structure so that might not be the best approach. As you can see, this limit is reached very quickly when only 250 enemies are engaging.

     
    Occuros and apkdev like this.
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Copy Entities package from /Library/PackageCache folder to /Packages, and you can freely modify sources without them being overriden.

    But as mentioned in that post, its probably worth re-evaluating the setup.
    Moving / allocating that many chunks is costly, and perhaps simple bool or bitmask would perform better.
     
    BigRookGames likes this.
  3. BigRookGames

    BigRookGames

    Joined:
    Nov 24, 2014
    Posts:
    330
    Ah, thanks.

    Going back over the code I realize that enabling and disabling a few flags can really increase the count drastically. I removed 9 flags from my enemy state system and put them into a single component. The count went from above 11,000 to 1,000 over the same scenario test.

    In fact, looking over the code again, I'm surprised it wasn't much higher considering that a single flag can potentially double the count. I just need to keep this in mind moving forward with the design, I wasn't aware of how quickly this can happen while scaling up.

    I also thought that moving these zero-sized components didn't move the data to a new archetype, but after speaking with someone from Unity apparently it does unless doing so to a chunk vs just an entity.