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

How should I manage large number of object on mobile

Discussion in 'Scripting' started by Le_Tai, Jul 30, 2017.

  1. Le_Tai

    Le_Tai

    Joined:
    Jun 20, 2014
    Posts:
    430
    What I need:
    • A lot of independent bullets
    • Run on mobile
    What I'm doing:
    • Bullet are gameobjects(pooled).
    • Each bullet has no component other than Transform.
    • Control all bullet from one script => mediocre performance :|
    What I'm tried:
    • Use struct to store bullet state. Graphics.DrawMesh to display
      • Fast.
      • Bullet meshes can't be batched => thousands of draw calls => Can't use on mobile :(
    • Like above. But use instanced material to draw bullets
      • Faster.
      • But ~60% mobile don't support GPU instancing :(
    • Like 1st. But combine all bullet into one mesh on-the-fly, then DrawMesh only once
      • Only 1 draw call
      • Too high CPU usage :(

    How can I improve the above strategies? What are others options?
     
    Last edited: Jul 30, 2017
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,444
    I abused a ParticleSystem to draw "many of the same things" with one draw-call on mobile.

    I used a ParticleSystem simply to render a whole lot of objects at specified positions from game-code. The particle system itself wasn't emitting any particles.

    The idea is to use an Particle[] array, update the array with (bullet) positions from your game-code when needed and assign it using ParticleSystem.SetParticles.

    This allowed me to render many objects with custom positions (and other attributes such as Color) with one draw-call only.

    Not sure if it's faster than what you already tried though.
     
    larku likes this.
  3. sefaenes

    sefaenes

    Joined:
    Jul 12, 2019
    Posts:
    22
    @Le_Tai any improvements? advices? especially mobile?
     
  4. Le_Tai

    Le_Tai

    Joined:
    Jun 20, 2014
    Posts:
    430
    ¯\_(ツ)_/¯

    Make do with less is what I did. Maybe GPU instancing is better supported after 3 years?