Search Unity

How much Overhead for EntityManager.AddComponent(Data) and RemoveComponent

Discussion in 'Entity Component System' started by dongyiqi, Apr 19, 2018.

  1. dongyiqi

    dongyiqi

    Joined:
    Nov 7, 2017
    Posts:
    11
    I have an idea that using component to drive AI.
    eg. FindTargetComponent will be added If a pawn AI need to find a target. FindTargetComponent will be removed after a target is found. FindTargetSystem will handle the task of finding a target.

    But I don't know how much it cost for the calling fo AddComponent and RemoveComponent.If these functions called 1000 times per frame,will is be OK?
     
  2. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,243
    If you have to instantiate something every frame (god forbid multiple times), you've already taken a weird turn somewhere.

    Just make a test script to measure the feasibility of such an idea.
     
  3. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Our intention is to make sure that adding and removing components at runtime with ECS is fast enough that it is a thing you can do at scale.

    Right now it's doing more work than it should be.

    Performance right now depends on the amount of other components on the entity. Best would be to measure for your specific game.
     
    FROS7, MadeFromPolygons and optimise like this.
  4. dongyiqi

    dongyiqi

    Joined:
    Nov 7, 2017
    Posts:
    11
    Thank you for your reply.
    I'm curious about what happens componentData added or removed from an entity.Is there lots chunks of memory are deleted, new, or move ?
    Is there any document about such things?
     
  5. GabrieleUnity

    GabrieleUnity

    Unity Technologies

    Joined:
    Sep 4, 2012
    Posts:
    116
    @dongyiqi There is no documentation because the implementation is not definitive, but you can look at the source code to get an idea of what's going on.