Render Order Doesn't Work With Overlapping Objects

I am creating a program that has multiple game objects in the scene with various shapes, sizes, and rotations. The problem with this is that they often overlap and the game is rendered based on which object’s center position is closest to the camera.

For example, I created two cubes, one that was 2x2x2, and one that was 1x1x1. Even if the smaller cube is fully within the larger, if its center position is closer to the camera, it renders over the larger cube.
Is there a way to tell Unity to only render the parts of a game object that are not behind a part of another game object? If a sprite is sticking halfway out of a cube, can I render just the part that is sticking out instead of the entire sprite?

I am new to Unity and this may be a simple fix, I don’t know, but I haven’t been able to find anyone with the same problem. Thanks for your help!

I found the same issue here: Intersecting sprites - Questions & Answers - Unity Discussions
This issue was solved using a custom shader and material using Shader Graph. Changing the Surface setting to opaque made the sprites render how they should. The rest of what I did was basically mimicking the default sprite renderer. Attached is a screenshot of the final shader.