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

GPU Instancing for 2D sprites and UI elements

Discussion in 'General Discussion' started by Kastalche, Jun 21, 2023.

  1. Kastalche

    Kastalche

    Joined:
    Nov 21, 2022
    Posts:
    3
    Hello, I am new to profiling. I want to know if there is a way to make a lot of objects of the same type but sprites and ui elements to draw on one draw mesh callback exactly how the GPU instancing option makes it for 3d meshes.
     
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    Use dynamic batching for sprites. Any sprite less than 300 vertices will be batched;
    As for the UI - investigate what's breaking the batching.
    Make sure you're using sprite atlas and all UI / sprite resources are in it. (see Frame Debugger)

    Instancing is usually slower than dynamic batching and you don't want it to be enabled for them at all.
    Unless for specific cases that are affected by material parameter changes etc.
     
    Last edited: Jun 21, 2023
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    And put all sprites in a spritesheet.
    But note that UI and regular sprites will be on different draw calls. I don't think they can ever batch together even if you use the same sprites/textures.
     
  4. Kastalche

    Kastalche

    Joined:
    Nov 21, 2022
    Posts:
    3
    Thank you,Is it a problem that I add them with Instantiate method?
     
  5. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    It does not matter.