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

batching images loaded dynamically.

Discussion in 'General Graphics' started by Saxi, Dec 12, 2014.

  1. Saxi

    Saxi

    Joined:
    Jun 28, 2013
    Posts:
    381
    I'm having an issue trying to find a solution to this.

    I need to assign sprites to sprite renderers dynamically via only code. (I have list of folders that contain images and a mapping file documenting what image is in the folder loaded).

    So I have the folders under resources, and I am using resources.load to load the images into sprite renderers. When I do this though, I cannot use sprite packing and each sprite is coming in a separate draw call.

    How can load images dynamically via code while batching (preferably static) draw calls?
     
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    You'll have to use a sprite sheet texture instead of separate image files.
     
  3. Saxi

    Saxi

    Joined:
    Jun 28, 2013
    Posts:
    381
    Is there any way to take advantage of Unity's auto sprite sheet creation?
    Making sprite sheets is time consuming as I have 4,000 images, and I have hundreds of mapping files that use the image name to control how the scenes are created all dynamically.
     
  4. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I think the sprite sheet building is an 'editor' functionality, not a runtime one.
     
  5. Saxi

    Saxi

    Joined:
    Jun 28, 2013
    Posts:
    381
    I understand it only being a design time thing.
    I just can't figure out a way to get batched draw calls when using resource folder for sprites unless I package them outside of Unity using a third party tool (like Texture Packer).
     
  6. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    this addon combines meshes, and atlases their textures: http://forum.unity3d.com/threads/mesh-baker-by-digital-opus-released.159258/

    maybe you could look at the source code and see how the texture atlasing is done, and then use that method to generate your own atlases at runtime from the dynamically loaded images
     
  7. Saxi

    Saxi

    Joined:
    Jun 28, 2013
    Posts:
    381
    An atlas/sprite sheet (either via Unity or externally) is only way to get the draw calls to batch right?