docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Archetypes concepts

    An archetype is a unique identifier for all the entities in a world that have the same unique combination of component types. For example, in the following diagram, all the entities in a world that have the components Speed, Direction, Position, and Renderer and no others share the archetype labelled X. All the entities that have component types Speed, Direction, and Position and no others share a different archetype labelled Y.

    When you add or remove component types from an entity, the world's EntityManager moves the entity to the appropriate archetype. For example, if an entity has the components types Speed, Direction, and Position and you remove the Speed component, the EntityManager moves the entity to the archetype that has components Direction and Position. If no such archetype exists, the EntityManager creates it.

    Important

    Moving entities frequently is resource-intensive and reduces the performance of your application. For more information, refer to the documentation on Structural change concepts.

    The archetype-based organization of entities means that it's efficient to query entities by their component types. For example, if you want to find all entities that have component types A and B, you can find all the archetypes with those component types, which is more efficient than scanning through all individual entities. The set of existing archetypes in a world tends to stabilize early in the lifetime of a program, so you can cache queries to get faster performance.

    An archetype is only destroyed when its world is destroyed.

    Archetype chunks

    All entities and components with the same archetype are stored in uniform blocks of memory called chunks. Each chunk consists of 16 KiB and the number of entities that they can store depends on the number and size of the components in the chunk's archetype. The EntityManager creates and destroys chunks as needed.

    A chunk contains an array for each component type, plus an additional array to store the entity IDs. For example, in an archetype with component types A and B, the chunks each have three arrays: one array for the A component values, one array for the B component values, and one array for the entity IDs.

    The arrays of a chunk are tightly packed: the first entity of the chunk is stored at index 0 of these arrays, the second entity of the chunk is stored at index 1, and subsequent entities are stored in the consecutive indices. When a new entity is added to the chunk, it's stored in the first available index. When an entity is removed from the chunk (either because it's being destroyed or being moved to another archetype), the last entity of the chunk is moved to fill the gap.

    When an entity is added to an archetype, the EntityManager creates a new chunk if the archetype's existing chunks are all full. When the last entity is removed from a chunk, the EntityManager destroys the chunk.

    For information on how to manage chunk memory, refer to Managing chunk allocations

    Archetypes in the Editor

    The Archetypes window lists the archetypes of all the worlds in your project and it shows the amount of allocated and unused memory of each archetype.

    In the Editor, the following icon represents an Archetype: .

    Additional resources

    • Structural changes concepts
    • Managing chunk allocations
    • Archetypes window

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Archetype chunks
    • Archetypes in the Editor
    • Additional resources
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)