docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Remove components from an entity

    To remove components from an entity, use the EntityManager for the World that the entity is in.

    Important

    Removing a component from an entity is a structural change which means that the entity moves to a different archetype chunk.

    From the main thread

    You can directly remove components from an entity from the main thread. The following code sample gets every entity with an attached Rotation component and then removes the Rotation component.

    public partial struct RemoveComponentSystemExample : ISystem
    {
        public void OnCreate(ref SystemState state)
        {
            var query = state.GetEntityQuery(typeof(Rotation));
            state.EntityManager.RemoveComponent<Rotation>(query);
        }
    }
    

    From a job

    Because removing a component from an entity is a structural change, you can't directly do it in a job. Instead, you must use an EntityCommandBuffer to record your intention to remove components later.

    In This Article
    • From the main thread
    • From a job
    Back to top
    Copyright © 2024 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)