Search Unity

Subscenes and Terrains ?

Discussion in 'Entity Component System' started by Opeth001, Aug 7, 2019.

  1. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,116
    hi everyone,
    i there any way to convert a terrain to entity using subscenes ?
    if not, is it possible to convert a terrain to a simple GameObject then convert it using subscene ?
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    Terrains are not supported in subscenes yet.
     
    Opeth001 likes this.
  3. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,116
    Is there any workaround ?
    Like converting the errain to a mesh and use it with the regular conversion workflow ?
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    Just put it in a regular scene and load it normally? (or just the parent scene)

    Shouldn't be that hard to write a simple system to load a terrain along with a subscene.
     
    Last edited: Aug 7, 2019
  5. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,116
    i know but i wanted something pure ^_^.
    also for an unknown reason unity freezed like 10 times in 30mn while using the paint tool, do you guys faced this problem before ?
    * it never got that much of freezes before using terrains.
     
    nicolasgramlich likes this.
  6. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    What benefit would you gain for having terrain be "pure"? It isn't like you are going to have a whole bunch of them that performance matters. If necessary, you can use what Unity does with Lights and write your own terrain converter that utilizes a terrain pool for rendering.
     
  7. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,116
    actually yes! in my case ill have arround 784 peace of terrain. each peace is 50x50m, and the whole map is 1400x1400m, so iterating over them in a linear + parallel way plus enabling/disabling their renderers will always be better than the normal GO workflow, that's why ECS is awesome.
     
  8. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    50x50m is really small for a terrain. I would expect that you could drop your terrain count by 2 orders of magnitude.

    But if you still decide to stick with that many terrains, the challenge is you still need a terrain renderer to render each terrain. So either you need to pool terrains like Unity.Rendering.Hybrid does for lights, or you need to use hybrid.
     
    Opeth001 likes this.
  9. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    I can't think of a use case where this would be a good approach. Are you simply wanting to not render parts of the map? Like if it was a top down game for example?
     
  10. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,116
    yep! it's a Top Down game :)
    and im culling the whole map ( Trees, cars, gras, ground props... ) using a SCD int2 called region.
     
  11. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,116
    the map culling system always activates the 9 regions around the player, so when the player changes region the system enable/disable the right entities by querying them using the SCD and add the Disabled CD with a batch operation which is incredibly fast.
     
  12. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Frustum culling is incredibly fast also. So you have to consider your approach on a case by case basis, measured against the complexity involved. Your approach for terrains involved a lot more complexity. And your potential gain was always extremely small. And I'm being gracious there because with how terrains are actually rendered, and your map size, there is just no way your approach would win out.
     
  13. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,116
    I don't understand how my approach can be slow, I juste query for all entities with a SCD (Which is fast) and Add/Remove the Disabled CD using a Batch operation with the EntityQuery it self(which is fast too). So the operation is done by chunk not by entity.
    Also this operation is not executed every frame like the Frustum culling, but only when the player reaches the minimum and maximum bounds of his current region, so arround 1op / 15 ~50s (The fastest code is the code which does not run )

    Culling System Logic:
     
    Last edited: Aug 8, 2019
  14. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,116
    yes for the Moment the 50x50 is just a tweakable parametre and will certainly be changed in the future, i try to renderer as less as possible cause it's a Mobile Game and i try to consider the wide variety of low end devices.
    but the player will always have 150x150 active space (9 regions).

    the only real problem im facing now is i cant add/remove the Disabled CD to subscene entities when using the StaticEntityOptimization Component, cause all it's chunks are locked and the renderer system without this component is having poor performance.
     
  15. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Measure the performance of just having a single 1400x1400 terrain vs 9 that are 50x50. The single terrain has a lower total rendering cost.
     
  16. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,116
    for Esthetic reasons it's just impossible for us to use a single peace of terrain for the whole map. ( holes .... )