docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method MoveComponent

    MoveComponent<T>(EntityManager, Entity, Entity)

    Safely move a managed component on the source entity to another destination entity.

    Declaration
    public static void MoveComponent<T>(this EntityManager manager, Entity src, Entity dst) where T : class, IComponentData, new()
    Parameters
    Type Name Description
    EntityManager manager

    This entity manager.

    Entity src

    The Entity the managed component will be removed from. This entity must have a component of type T.

    Entity dst

    The Entity the managed component will be added to. If this entity already has T with a different value than src, the existing value will be removed and disposed before the new value is assigned.

    Type Parameters
    Name Description
    T

    The managed component type.

    Remarks

    If the source and destination entity are identical, no operation is performed.

    This operation seems similar to

    value = GetComponentData<T>(src); AddComponentData(dst, value) RemoveComponent<T>(src)

    But for managed components which implement IDisposable, calling RemoveComponent will invoke Dispose() on the component value, leaving the destination entity with an uninitialized object.``` This operation ensures the component is properly moved over.

    In This Article
    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)