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

Is the change of sprite in sprite renderer inefficient in runtime?

Discussion in 'Scripting' started by mahdiii, Nov 12, 2016.

  1. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    853
    I have one 2d animation (100frames i.e 100 separate images). is the change of sprites inefficient when it is animated? does it generate more batch? I can not use spritesheet because every image is 4096*4096.
     
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Each sprite which is different texture will be different draw call, so it will be more inefficient the more changes are rendered. So test it. Pointless worrying if you have 10 sprites moving around.
     
    mahdiii likes this.
  3. romatallinn

    romatallinn

    Joined:
    Dec 26, 2015
    Posts:
    161
    Do you mean that every single image of 100 is 4096*4096? That is definitely not good. What kind of animation do you have? It has to be simplified anyhow. The problem is more in size of images you will have at the end. Visual art always takes a huge part of the total build's size.
     
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yeah does seem insane but each to their own...
     
    mahdiii likes this.
  5. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    853
    I need high resolution images, yes each image has 2048 or 4096 size. I want to use projectors devices and advertisement applications (interactive advertisement) so we need high resolutions images. it is not android game!!
    I see only 2 batches in stats! I have only one sprite object with animator (100 sprite images)
     
  6. romatallinn

    romatallinn

    Joined:
    Dec 26, 2015
    Posts:
    161
    Again, you want to use those images for interactive ads or what? I just want to understand how those images will look like. Sometimes it is possible to simplify the images into a few parts. So you can keep those parts that don't change, and interact with those that do change, if you understand what I mean. Try to think critically on your images. How could you simplify them, so you are not supposed keep full images of 100s of them. Or send here an example of the image. So, we could suggest a solution. Although, you the game is not for mobiles, it is important to low the size of the final build as much as possible. I heard a lot of complains that new CoD Infinite Warfare weights >80GB for PC, even though it has a huge range of content. I do not think that your game will be as filled by useful content.
     
    mahdiii likes this.
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    It's an installation using projectors, not a game on a computer or whatever.

    Anyway, if what you're doing runs fine, then don't worry about it.

    --Eric
     
    Kiwasi likes this.
  8. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    853
    Thank you but my question was the change of sprites does not affect on batch count?
    Code (CSharp):
    1.  
    2. public Sprite[] sps;
    3. SpriteRenderer sp_renderer;
    4. void Start(){
    5. sp_renderer=GetComponent<SpriteRenderer>();
    6. }
    7. void IEnumerator(){
    8. int i=0;
    9. while(true){
    10. sp_renderer.sprite=sps[i];
    11. i=(i+1)%sps.Length;
    12. yield return null;
    13. }
    14. }
    15.  
     
  9. JoshuaMcKenzie

    JoshuaMcKenzie

    Joined:
    Jun 20, 2015
    Posts:
    897
    things that affect batching are when either two images from completely different source textures overlap each other (each text font is considered its own texture), or when the whole group of UI Elements in a canvas are not co-planar with each other, or when drawing a canvas in world mode (because the extra perspective requires the pipeline to make sanity checks leading to more batching).

    Rendering a canvas in Camera mode doesn't cause more batching but it does slow down the rendering (since the pipeline now has to wait on when the camera is ready)

    Batches are on a per frame basis, with the first batch in the frame always the "Clear" call

    if only one sprite is used per frame it won't affect batching.
     
  10. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    853
    thank you. so you say it doesn't affect on batch count but if we change sprites(one sprite renderer) in runtime it can cause slow ? what solution does it have to improve fps
     
  11. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    853
    load time is high because of high resolutions frames. Do we need to use async load at first?
     
  12. JoshuaMcKenzie

    JoshuaMcKenzie

    Joined:
    Jun 20, 2015
    Posts:
    897
    honestly its just that your resolutions are just too high.

    Compared to a "standard" HDTV that loads a 1920x1080 resolution at 24 frames per second to your 4096x4096 at 30~60 fps and your basically trying to load data upto 20 times faster than the tv devices specifically designed for high data throughput.

    this is the same technical challenge that certain VR apps are running into. the hardware just can't load that much data that fast.

    one thing you might be able to do is pre-load all the sprites into the scene (since you only have 100) then pool each sprite into its own sprite renderer and cycle through and only show one at a time. the Batchrender will skip disabled objects so the other sprites won't affect batches when they are disabled.
     
    mahdiii likes this.
  13. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    853
    Thank you , I don't have any problem in runtime. I only have high load time when a scene is loaded.
    If one image is 1920*1080 (1mgb) and an animation has 200 frames. it becomes 200 mgb. So suppose we have many objects and many animations for them!! We need alot of ram.
    You say I create many sprites and pool them (active disactive) so I don't need to load all frames. perfect but the controller is hard. I want to use animator controllers. If I do your opinion I must write my own animator controller (conditions transitions triggers etc)
     
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Yes, many high-res textures = much RAM, no way around that. You could try using a movietexture instead, since video formats are designed to compress moving images.

    --Eric
     
    mahdiii likes this.
  15. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    853
    it is good solution but movie texture does not support alpha channel (transparency)
    and can not control completely (reverse,play, pause, transition,conditions like animator controllers)
     
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    They're replacing movietextures with a new video system soon (5.6 according to the roadmap).

    --Eric
     
    Ryiah likes this.