Reputation: 147
(Unity2D) Is there a way to set a custom sorting point for a spriterenderer without changing the pivot? I only see default and custom based on pivot as options, but I don't know if you can change them via script, has anyone done something like this?
Upvotes: 1
Views: 2395
Reputation: 31
This is a workaround that works for me, albeit a bit odd:
Make your game object child of an empty GameObject, and add a Sorting Group component to the empty GameObject. Move the empty GameObject to where you want your "pivot" to be.
This way, the empty parent with only the Sorting Group component will be used to sort. You'll have to add any movement code and colliders to the new parent, instead, so effectively you'll be moving the empty game object, and the child is just responsible for rendering the sprite with respect to the "pivot."
Upvotes: 3
Reputation: 2306
By default, a Sprite’s Sort Point is set to its Center, and Unity measures the distance between the camera’s Transform position and the Center of the Sprite to determine their render order.
To set to a different Sort Point from the Center, select the Pivot option. Edit the Sprite’s Pivot position in the Sprite Editor.
No, there is not a way to change the sorting point without changing the pivot. The sort point is the same as the sort point. What is your use case that you need to change the sorting point and cannot use sorting layers?
Upvotes: 0