Search Unity

Code vs Prefab

Discussion in 'Entity Component System' started by Zeraphan, Mar 5, 2020.

  1. Zeraphan

    Zeraphan

    Joined:
    Nov 20, 2019
    Posts:
    14
    If I spawn 10,000 entities that have a cube mesh created entirely from code I can have them moving around at 100 FPS. If I instead create a cube prefab and convert it to an entity to use as the base for the 10,000 entities they move at 30 FPS.

    What causes that extreme drop in performance?
     
  2. Fribur

    Fribur

    Joined:
    Jan 5, 2019
    Posts:
    136
    Do you see a difference in the number of chunks generated via those two approaches?
     
  3. Zeraphan

    Zeraphan

    Joined:
    Nov 20, 2019
    Posts:
    14
    Code: 201 chunks
    Prefab: 290 chunks
     
  4. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    Check the timeline view in the profiler. It is pretty good at pointing out which jobs slow down.
     
  5. Zeraphan

    Zeraphan

    Joined:
    Nov 20, 2019
    Posts:
    14
    Updated yesterday from Entities 5.1 to 7.0 and now only the prefab created entities even show up, the ones made purely in code no longer are visible. So I will have to solve that mystery first before I can get back to why one was working better than the other.

    Fixed rendering: Apparently the RenderBounds were being added automatically (or somehow not needed) previously and weren't with 7.0, so adding those brought everything back.
     
    Last edited: Mar 6, 2020
  6. Zeraphan

    Zeraphan

    Joined:
    Nov 20, 2019
    Posts:
    14
    I am not really versed in understanding all aspects of the profiler. The only thing I can really determine is that all things rendering are taking twice as long on the Prefab timeline vs the Coding timeline.

    Prefab Image Link
    Coding Image Link
     
  7. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    3.69 ms vs 2.96 ms. The difference here is that converted prefabs have extra components attached to them for blob assets and subscene-related stuff. This causes the number of entities per chunk to fall and the chunk count to rise. The hybrid renderer has issues where it does unexplainably slow operations per chunk.