Sprite Swap / Resolver and Sprite default pivots issue

Hello there !

I'm importing a character made in photoshop and saved as a *.psb file.
Some parts of the character will be animated thanks to bones based animation and some part of the character will be animated with frame by frame animation technique (like eye blink for example).
So it is kind of an hybrid animation

I red all the documentation about sprite swapping experimental feature and it sounds just perfect for my use case so I set some categories to my sprites that I want to be able to swap (eye-left, eye-right, and so on).

The main issue issue is that when I swap the sprites they do not stay in place like in the original *.psb file because they all have a default centered pivot.

I think there is no point at all by setting all the pivot manually because I needs a very precise calculation of the pivot point of every sprite depending on how Unity slices them and their position in the original *.psb file.

Is there a way to tell Unity to set pivot to each sprites that belong to a "category" so that the sprite stays in place when you swap them. If not the feature of sprite swap is useless for sprites that have not the same exact size and it is very sad (My opened eye is bigger than the closed eye layer, see what I mean?)

Thanks for your help and your amazing work

2 Likes

Hello @Rafarel ,
We do not have a way to set the pivots in the way you described. The closest I can think of is creating your own import post processor to update the pivot when importing a Sprite/Texture.

The current solution to this is to manually update the pivot of your Sprites. Apart from the time it takes to set the pivots up, is there anything that prevents you from doing this? This is an area we are currently looking into to see if it needs an improvement, but before we want to get our hands dirty, we want to fully understand the issues developers are facing with the current flow.

Thanks!

Hello @Ted_Wikman ,

About the "creating your own import post processor to update the pivot when importing a Sprite/Texture." honestly I don't know where to start. This issue is related to only one asset of my whole project so I don't know if writing code for just one single animation is a great idea, but it can be a good challenge so why not :)

I think we can have several different approach.

1/ The sprite slicing auto adjust the pivot of each sprites that are on a same folder in the *.psb file
OR
2/ The sprite slicing auto ajust the pivot of each sprites that share a common category

On every of the two previous scenarios all the sprite have to have a position that overlap in the original psb file.

I don't know if adjusting the pivot is a good idea...

Maybe it can be the responsibility of the Sprite Resolver component to keep an offset whatever the pivot is so that all the sprites appears at the exact same position than in the psb file ?

@Ted_Wikman I can send you a minimalist Unity project with a single *.psb file and a scene in it to show you what are the issues I'm facing as a developer.

The demo project is already ready tell me if you are interested by experimenting my use case

6589087--748645--upload_2020-12-4_15-57-4.png

Have a nice day!

1 Like

Hello @Rafarel ,
Thanks for the ideas on how to improve the pivot flow. I'll share this thread with the rest of the team to add to the pivot conversation we are having. I would also love to get my hands on that project. Then we can both see the issues you are faced with, and also try a few approaches to see how we would solve it in a more convenient way.
You can write me a DM and share a link. Let me know if you need a way to upload the project.

Also, let me know how the import post process works out for you, if you try it out.

Again, thanks a lot for helping us improve the toolset with feedback and ideas!

Hi @Ted_Wikman ,

I just DM you with a link to my sample project
Feel free to share the result here with the Unity community.

Have a nice day

2 Likes

Thank you Rafarel! Ted has shared your sample project with us last week and we have been playing with it. This Sprite Swap pivot issue is tricky and is certainly a problem we want to address. Thank you for taking the time to share with us in detail. Let us keep you posted on the updates as we try to figure out a good solution for this.

1 Like

Thanks @suxiangting ! Happy to help if it can improve Unity!
Tell me if you need anything else.

1 Like

I'm also having trouble with this issue.

Thanks for sharing @RealMcCoyGames

It is not a great experience as your video shows. A question out of curiosity, how come your pivot has to lie so far off from the Sprite?

@Ted_Wikman

Well it doesn't lol. I'm either doing something wrong or it's a bug (relatively new to unity although I have background in web dev, and dabbled in game dev over the years). The beards are in pretty much the same spot in both PSB's. Unity was changing the pivot point for some reason. I think it's working correctly now although not sure what I did to resolve.

In case somebody stumbles across this and also uses 2D Animator:

Enabling "Auto Rebind" on the SpriteSkin makes adjusting the pivot point obsolete and positions the sprite correctly (tried with 2D Animator 6.0.5).

To add some more flavour to this comment, when you skin your sprite mesh (connect the vertices to bones), the pivot point is not being used, since each vertex in the mesh is positioned in relations to the bones it is skinned to, every frame. This has been the case since we first introduced the Sprite Skin component.

If you are swapping two Sprites with the same bone structure, the swap will work without enabling Auto Rebind. If you are swapping between two Sprites with different bone structures, you need to enable Auto Rebind so that the Sprite Skin component can update the bone list and deform the new sprite correctly.

You can read more about Sprite Swap and Pivot points in this new section in our 2D Animation documentation, and if you are curious about Auto Rebind, you can read more about it here.