Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Is there a way to replace a sprite in a spritesheet while maintaining "Bind Poses"?

Discussion in '2D Experimental Preview' started by yuch3n, Mar 25, 2019.

  1. yuch3n

    yuch3n

    Joined:
    Sep 26, 2018
    Posts:
    26
    I managed to rig my 2d character up with bones and have her animating. However, now I want to try to change the colour of her clothing. I tried importing the new clothing as a png and replacing the Sprite field of one of the Sprite Renderers in the hierarchy with the new sprite, but now the Sprite Skin component gives me the warning "Sprite has no Bind Poses", and the sprite is being rendered with no mesh deformation at all. Is there a way to swap out images without losing the bind pose information (still a bit unclear of what that is exactly)?
     
  2. Leo-Yaik

    Leo-Yaik

    Unity Technologies

    Joined:
    Aug 13, 2014
    Posts:
    435
    The Sprite that you swap in will need to have the same number of bones influencing the Sprite. This means that you will need to rig the new Sprite the same way you rigged the previous Sprite.

    You can also try selecting the Sprite in Skinning Module Sprite Editor Window, press copy, switch over to the new Sprite, select it and press paste.
     
    Kshesho likes this.
  3. ArseneySorokin

    ArseneySorokin

    Joined:
    Jan 23, 2013
    Posts:
    63
    Hello,

    Any way to do this in code during run-time?
    Where in the sprite are the bind poses saved and how can I copy them to a different sprite?
     
  4. games4ever

    games4ever

    Joined:
    Jan 23, 2014
    Posts:
    11
    Hello @yuch3n

    What about just replacing the sprite texture itselft for the new one?
     
  5. GoblinGameWorks

    GoblinGameWorks

    Joined:
    Sep 14, 2019
    Posts:
    13
    https://forum.unity.com/threads/changing-animation-sprites.213431/

    this thread has video at min 20:00 with C# script code used to swap out your original sprite sheet for another. The only issue I see here is the number of sprites within your sprite sheet I believe all your sprite sheets need to match in quantity of individual sprites within the sheet... unity loads them instead of your originals and it is all contingent upon the naming structure of the sprites within the sprite sheet.

    So if your new sprite sheet has more sprites like other dangling accessories or an extra arm etc. I don't believe this method will work... or at least I haven't found the workaround yet.
     
  6. LeleUnity

    LeleUnity

    Joined:
    Jul 30, 2016
    Posts:
    97
    I don't understand Why I should copy the rig. According to the manual: "
    1. Add the Sprite Library component to the same GameObject, and assign the new Sprite Library Asset set up in step 3 to the Sprite Library Asset box.

    2. Add the Sprite Resolver component to the same GameObject.
      " and so on...
      I have firstly rigged my character, then I did what I cited from the manual and then I switched a body part, getting Sprite has no binding... WHY? How solve it? Why doing like the manual is not working?
     
  7. datagreed

    datagreed

    Joined:
    Sep 17, 2018
    Posts:
    42
  8. LeleUnity

    LeleUnity

    Joined:
    Jul 30, 2016
    Posts:
    97
    In order for SpriteSwap with SpriteSkin, the Sprites that is swapped in needs to have the same number of bones as the original Sprite.

    If you look at the Rikr examples, all the swappable Sprites are rigged with the same number of bones.

    So in your particular case, you will need to rig the 'face swap' sprite with a single bone (just like you did with the 'face' sprite in cipresso).

    We recognise this is not ideal at the moment, and we are still looking for a solution for this.

    For the case of Weapons, if the weapons does not need to deform (like a Sword or a Shield) it can placed in the SceneView so that it follows the transform of the body part.
     
  9. ruaangrobler0

    ruaangrobler0

    Joined:
    Feb 13, 2019
    Posts:
    2
    I'm a little late to help the OP, but I have some advice that can help others. You can drive sprite colour using some basic colour blending math in the node-based shader editor thingy (sorry, I'm not a regular Unity guy, come from a 3D CG background though). Basically make the default sprite white in the places you want to drive, then multiply by colour, and use RGB mattes to isolate the places you want to use. You can even use overlay math with lighter and darker areas to keep lighter and darker tones. - this is not a tech example, but a colleague and I recently did it here:

    All those characters were sprites on bones with user-selected colour for 3 key items of clothing.
     
    yuch3n likes this.
  10. yuch3n

    yuch3n

    Joined:
    Sep 26, 2018
    Posts:
    26
    Cool! My use case was a bit more complicated because we wanted to swap out the clothing type entirely, but this is a great way to add variety even without that.
     
  11. LeleUnity

    LeleUnity

    Joined:
    Jul 30, 2016
    Posts:
    97
    could you show the code for that?
     
  12. Leo-Yaik

    Leo-Yaik

    Unity Technologies

    Joined:
    Aug 13, 2014
    Posts:
    435
    We will trying to address this issue with the new version 6.0.0. Unfortunately this will only go with Unity 21.1
     
  13. DryreL

    DryreL

    Joined:
    Feb 23, 2020
    Posts:
    49
    Still no luck?
     
  14. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    906
    @DryreL a fix for this landed in 2D Animation 6.0, Unity 2021.1.
    You can read more about it here.

    Let us know if this feature fixed your issue.
     
  15. dramatemple

    dramatemple

    Joined:
    Apr 27, 2013
    Posts:
    14
    In our case, we are downloading the assets from the server and creating a sprite atlas on runtime. These assets do not have any Bind Poses, hence the sprite swapping isn't functioning. Is there a way to create Bind Poses on runtime? Been using Sprite Renderer and Sprite Skin since the game is 2D but if the API is not there also can switch to SkinnedMeshRenderer.
     
    tonytopper likes this.
  16. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,321