Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to batch draw calls with mod content (from StreamingAssets)?

Discussion in '2D' started by tknippenberg, Feb 1, 2023.

  1. tknippenberg

    tknippenberg

    Joined:
    Feb 15, 2017
    Posts:
    13
    In my 2D game (screenshot below) objects are put on top of each other by setting the sortOrder based on the Y coordinate. To reduce the number of draw calls I ended up putting (almost) all sprites into 1 big Sprite Atlas, which was an acceptable solution.

    For my next project I would like to support some forms of modding, allowing players to add new types of objects, like another type of fountain for example.
    Assuming I would have to load these assets through StreamingAssets (I'm open for alternatives ofc), how would I go about optimizing the number of draw calls? As these assets need to be read at runtime, this seems very different to me than the Atlas approach.

    Any pointers how other games approach this are welcome as well of course.

    Thank you for your help!

    Screenshot.jpg
     
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,503
    Since Sprite Atlas doesn't support building a new atlas at runtime, the only solution is to create your own spritesheet builder.

    Streaming Assets or some other folder: turn PNGs into textures, shove into spritesheet.
    Alternatively, have your modders create an asset bundle and then digest its sprites' textures into a spritesheet.

    Of course, the absolute easiest thing is to do nothing and just let mods break batches. Most players have the expectation that mods make performance worse. If you have people complaining about mod performance, then that might be the best time to consider building your own atlas creator.
     
  3. tknippenberg

    tknippenberg

    Joined:
    Feb 15, 2017
    Posts:
    13
    Thank you, I'll check out the resources you've shared. For my previous game I initially started with loading assets at runtime but I ran into issues (like artifacts at the slice points at certain zoom levels, and couldn't get it to batch). Hopefully your pointers help! :)

    Of course, the absolute easiest thing is to do nothing and just let mods break batches.
    This is also an option I'm considering, but it seemed sensible to at least think about it early on in the process for a bit. If there is a magic way to achieve this it wouldn't hurt knowing about it rather sooner than later ;-)