Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Best approach to having 10,000 individual lines on screen (line renderer is bad).

Discussion in '2D' started by Valynna, Mar 19, 2022.

  1. Valynna

    Valynna

    Joined:
    Apr 1, 2021
    Posts:
    39
    I have a very large number of hexagonal cells, each of which has 6 "walls" which consist of a button (aligned onto the wall), a line renderer that renders the brown part, another linerenderer which renders a white outline, and a third line renderer below that which renders the final black outline. Now, most of these are turned off (because of overlapping walls) (so about 600 hex cell game object, with 6 cell wall game objects each (each wall has a line renderer on it, and each with 2 child game objects that also have line renderers on them.). Taht's about 600*6*3 = 10,800 game objects. Subtracting the hex cell game objects (which do have meshrenderers), that's still 10,200 line renderers!

    This was no problem when the map was 1/4 this size! But it's not a very scalable solution. As I move to larger and larger maps, this obviously is causing issues with performance. But before I start wildly stabbing in the dark about what to change and how to change it, I wanted your thoughts.

    How would you go about doing this? upload_2022-3-19_21-46-33.png
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,768
    I think I would use a custom geometry creator that would create the hexes and lines at runtime.

    You could subdivide them into areas and only update areas that change.

    I was curious so I made a little Make Lines 2D script that "runs" 1000 lines onscreen and added it to my MakeGeo repository... you're welcome to take a look for ideas.

    Look for the
    MakeLines2D
    scene.

    MakeGeo is presently hosted at these locations:

    https://bitbucket.org/kurtdekker/makegeo

    https://github.com/kurtdekker/makegeo

    https://gitlab.com/kurtdekker/makegeo

    https://sourceforge.net/p/makegeo

    Screen Shot 2022-03-19 at 9.55.35 PM.png

    Or perhaps make each hex cell a model that has pre-made center and edge geometry you just colorize by moving the UVs around?

    Those here with better shader chops might suggest the shader route, which I suppose might work well too.
     
    Last edited: Mar 20, 2022
  3. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
  4. Valynna

    Valynna

    Joined:
    Apr 1, 2021
    Posts:
    39

    To be honest, I've never worked with a "custom geometry creator" before.

    Could you give me a few sentence run-down, or a suggestion for a good readup? Google seems pretty sparse when it comes to that search.
     
  5. Valynna

    Valynna

    Joined:
    Apr 1, 2021
    Posts:
    39
    Ah no. Looking the your code now I get it.

    You're basically just making a class that makes the LR's, but using mesh's instead, and then taking advantage of static meshing, eh?
     
  6. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,467
    You asked about this problem before and left solution proposals unanswered..
    https://forum.unity.com/threads/any...gies-down-to-30-fps-all-in-rendering.1250935/

    Think it's more like you make one single mesh with all lines so you do not need separate game objects. Even with static rendering, the sole objects themselves would take their toll (because MonoBehaviors are sadly not very efficient in large numbers)

    By the way, there are a couple of free assets for hex maps:
    https://assetstore.unity.com/?q=hex&orderBy=6&free=true
     
  7. Valynna

    Valynna

    Joined:
    Apr 1, 2021
    Posts:
    39
    I tried all the suggestions given, none of which were well suited to my use case.

    Unfortunately, the same is true for hex map typesets.

    My game is really more about having arbitrary walls that can be moved around to form a maze, so it's not the hex grids per se that I'm interested in, but the walls themselves. Moving to a hex grid, for instance, makes voronoi maps and square maps later on impossible. HexCell is a child class of the Cell class, which can have an arbitrary number of walls. I doubt I'll ever use square cells, but the voronoi cells will likely happen one day.


    --
    Isn't that one static batching of meshes does though? It takes all the meshes you have which are marked static, and bakes them into one mesh? If not, then I must be misunderstanding satic batching.
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,533
    The point was to at least give the courtesy to reply to those trying to help, even if it wasn't the solution. Too many people ask questions here and then not reply and expect more answers.
     
    MousePods likes this.
  9. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,467
    It does that with the rendering, but the existence of the objects is still there. It's worth a try though.

    Another idea: You could use particles for the walls. If you enable GPU batching, 10k particles are easily manageable. ParticleSystems have a GetParticles and SetParticles method which allows to manipulate through code without "emitters" etc.
     
  10. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
  11. Valynna

    Valynna

    Joined:
    Apr 1, 2021
    Posts:
    39
    Ah. That's good. I can do that!

    Sorry! :)
     
  12. Valynna

    Valynna

    Joined:
    Apr 1, 2021
    Posts:
    39
    I'd read about this the other day. I think this might fix at least 2/3 of the problem.

    The white and black underside of the walls (The highlight and then lowlight for increased visibility) could definitely be run with particles, no problem. But the main one I thinks should still be run by a scriptable object because it needs to change material states as it takes damage (the walls are destructible), manage health, have collision detection, etc.

    Still. 2/3 of the solution is probably "good enough".
     
  13. Valynna

    Valynna

    Joined:
    Apr 1, 2021
    Posts:
    39
    The walls are destructible, take damage, and have a different visual damage state for each one. I'm worried that if I have to constantly rebake the mesh as walls get destroyed, take damage, or whatever, that this will end up with slow average frame rates, but higher spikes. Still - worth trying. Good idea.
     
  14. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    Did you have success with any approach?