Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Why is AddComponent so slow?

Discussion in 'Editor & General Support' started by TFlippy, Jul 28, 2017.

  1. TFlippy

    TFlippy

    Joined:
    Nov 12, 2014
    Posts:
    23
    When I was creating entities from code, I noticed that AddComponent<T>() that it produces quite large spikes in the Profiler. Turns out that single AddComponent<TrailRenderer> takes 0.80ms to execute and leaves behind 3.5 KB of data to be GC'd.

    What is it doing? It shouldn't even require Reflection to function as far I know.