Break 2D objects into multiple parts

Break 2D objects into multiple parts


C-sharp Unity Shader graph

Context

In my game, Colorless Odyssey, I have some elements that can be broken like boxes and vases and I had the choice to make a sprite for each part of the object or make a shader that will break the object into multiple parts automatically.

How the shader works

First, I use some variable to define the UV scale and offset to define a part of the sprite to display. I also have a variable to define the saturation of the object, because I need it for my specific game.

Using the UV, I cut the original sprite and apply an opacity mask to make the part appear.

Shader

I use a list of opacity masks to apply them to the parts of the object.

OpacityMask

Script to break the object

I made a manager that will break any object you give it with a list of SpriteRenderers to break them all at the same time if they are part of the same object. There is a lot of different settings to break the object like I want.

BreakCode

I can break any object in 2, 4, 8 and 16 parts with some randomness.

So I used this to break more things like enemies and some projectiles.

BreakEnemy

I also use a Rigidbody2D to apply a force to the parts of the object to make them move and bounce on walls.

How to use it

Per example, I use it here to break an enemy when he dies.

BreakEnemy

There is a lot of settings applicable to the object to break it like I want.

Limitations

There is some flaws in the system like the parts are unlit, I’ve tried to make them lit, but it was way too dark and I didn’t find a solution yet.

Also, the sprite that is broken into parts will not work correctly if it’s in an image with multiple sprites because the UV will not be correct.

Conclusion

This is really helpful to not have to make a sprite for each part of the object and it’s really fun to see the object break into multiple parts. I will use this system in my future games for sure.

I will maybe put it on the asset store if I can fix the lighting problem and made some documentation.

© 2025 Alexis Haldy