Search Unity

How to change sprite sheet for animation?

Discussion in '2D' started by DarkCooker, Feb 23, 2016.

  1. DarkCooker

    DarkCooker

    Joined:
    Jan 7, 2015
    Posts:
    119
    Hi All

    I have an animation of 2d sprites for a walking person.
    So each frame is showing different sprite from a sprite sheet.

    So if I want to change to another person with another sprite sheet, what should I do?

    Thanks very much
    M40
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    You can do this, but it's not straightforward. You can add a script which will change sprites in LateUpdate, which is after Animation does its work, so you can override your current sprite to the same one of a different set.

    Check out this video at 20:00 onward:
     
  3. DarkCooker

    DarkCooker

    Joined:
    Jan 7, 2015
    Posts:
    119
    Thanks for your share.
    I have a question. It handles Resource.Load and Array.Find in a every frame.
    Will it be too heavy for CPU?

    Thanks
     
  4. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    Relative to getting it at the start? Yes it will be heavy. Too heavy? Probably not. Still, if you only need to do that once, you may as well put it in start or awake. Array.Find isn't so bad, because the list won't be too long and you'll need to search them anyway. Unless you build a dictionary at start and do a lookup or something.
     
    theANMATOR2b likes this.