Search Unity

Question Best way to handle Sprite swapping

Discussion in '2D' started by urumizawa, Apr 27, 2021.

  1. urumizawa

    urumizawa

    Joined:
    Dec 30, 2020
    Posts:
    32
    Basically, I have a 2D multi sprite model with sprites for different parts (with skeletal animation in mind), everything has been going great until I started swapping sprites for the armor, hair..., the new sprite would be in another position.



    Changing the pivot point is an option but it takes way too much time and isn't really precise without fine tuning for a long while, and since some items of clothing like armors usually have additional sprites for arms and/or legss, the time needed to tune a single sprite X sprites in the piece of clothing is way too much time for a single piece of clothing, this will quickly get out of hand. took me around 15 minutes for 2 sprites, and there is still a seam between them.

    The pieces have been drawn on top of the character model and exported separately as psb files.

    From my understanding of the problem, and I am not experienced in this, unity ignores the original size of the entire file and instead puts an arbitrary rect around each layer and then uses its pivot point as the center. If that is the case, it doesn't suit my current needs at all. supposing that this is true, I imagine that exporting the files as standard pictures instead of .psb would do the trick but that would make things messy as hell for clothes that need more than 1 sprite both in unity and to edit later on with photoshop if needed;
     
  2. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    use photoshop actions to export each layer as .png
     
  3. urumizawa

    urumizawa

    Joined:
    Dec 30, 2020
    Posts:
    32
    Well, as specified above that would be very messy, imagine something like a long armor, it would have 2 sprites for the legs, 2 more for the arms besides the chest area so at least 5 sprites for a single clothing, heck without going that far, most chest pieces would have 3 sprites, most legwear and shoes would have 2 sprites which would clutter the sprites folder.

    Obviously it would be better than sprites that are out of place but i would rather keep that as a last resort (if they would even fix the issue). Isn't there an option somewhere that would solve this?
     
  4. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    well at the moment I have 156030 png files for my customizable characters, I think you can handle that much xd
     
  5. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    but now for real, this is really the correct way to do it, but if you arent up to it I will advise you to use texture2d to manipulate your layers and force them into the correct rect and center the pivot, even if i disagree with psb. workflows for this reason and more
     
    urumizawa likes this.
  6. urumizawa

    urumizawa

    Joined:
    Dec 30, 2020
    Posts:
    32
    well S*** then, since you ended up with that amount of png files, I am assuming you did try to work around it but ended up doing it anyway for lack of better means?

    just saw the follow up answer, well I guess PNG it is, since I have mobile in mind I would rather not add more scripts to correct every single sprite for every single character. I also don't want to spend the extra time figuring out how to do it if i can even figure it out when the other alternative would be better than that.

    I'll take your word for it and go for the PNG route. thanks a lot.


    edit: well appearently it didn't solve the problem, it made it worse somehow. may I ask you how you are setting this up?
     
    Last edited: Apr 28, 2021
  7. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    @urumizawa you said in your initial post that you are using skeletal animations. If the pieces you are swapping in are skinned (connected to the bone hierarchy), the pieces should not have an issue with pivot points, since each and every vertex in the Sprite mesh are being moved to the correct initial position every frame in the deformation step.

    How is your skeletal animation structured currently?
     
  8. urumizawa

    urumizawa

    Joined:
    Dec 30, 2020
    Posts:
    32
    Hello, thanks for the reply.

    Currently I didn't even animate yet but I did skin the character.

    To try to answer your question about the way things are set up, I exported a single psb with all the parts that I am going to be swapping (hair, chest, legs, arms, headwear, armwear, bodywear...) a then through code magic and scriptable objects, I get the sprite renderer of the parts specified in the scriptable object and swap the sprites, which is where I am at currently. wanted to fix the issue before animating.

    Just to reformulate the issue for clarification using the chestwear as an example, with the sprite exported in the psb file, it works perfectly, but as soon as I swap it for another chestwear, the position would be off even though they would match perfectly in photoshop. I don't know if it is the pivot point but that is what I concluded with my limited knowledge.
    To put it into perspective and again this is just what I think is happening and not necessarily what is really happening, imagine I have a tight T-shirt and a bulky armor with a giant spike coming out of the back, the center of the Tshirt corresponds to the center of the chest but the center of the armor would be offset due to the bigger size and the spike.
    Supposing that the default model (aka the psb file with everything) used the shirt for the chestwear, swapping in the armor will make the sprite out of place because of its center.


    but in case it matters, the bones do move correctly with the default sprites and so does the associated sprites.
     
    Last edited: Apr 28, 2021
  9. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Are you using 2D Animation's Sprite Swap flow to swap Sprites?
    Since you have skinned the whole character, it should swap and place the sprites on the right position. If you don't mind, could you send a sample project where this happens to me in a PM? Then I can take a closer look.
    Thanks
     
  10. urumizawa

    urumizawa

    Joined:
    Dec 30, 2020
    Posts:
    32

    I am using it, but for the body parts (hands,....) and not the clothing, I figured it would be too messy to use with the clothing since not all clothes have the same amount of sprites and cover the same things so I made my own script.

    I would love to but it is already late where I am to start unity and send you the requested sample project, so I appologize in advance but I won't be able to do it before tomorrow.
     
    Ted_Wikman likes this.