How Can I Make Sprite Sorting Layers 'Relative'?

Hello, I’m currently working on a modular weapon system for my project. My Game is a top-down, 2D roguelike, and so I put all of the gameobjects which need to interact with one another in terms of rendering order under the same sorting layer of “Interactibles” and render them in order depending on their Y-coordinate. The problem is that once I apply a weapon (which is assigned to a Transform position childed to the player), I want it to appear behind the player, but in front of everything else. So all of the objects are on the same sorting and order in layer, yet I need to somehow make the weapon, once equipped, to always render behind the player that equipped it yet in front of all other objects on the same layer. Is there any way to do something like this? (The images illustrate how the weapon renders in front or behind the player / other objects like in the attack animation) Any help is appreciated

You need to use a Sorting Group on the Player:

Sorting Groups allow you to group
GameObjects with Sprite Renderers
together, and control the order in
which they render their Sprites. Unity
renders Sprite Renderers in the same
Sorting Group together, as if they are
a single GameObject.


The sample showing in the docs is similar to your problem:
alt text