[Free Open Source] Unity 2D Destruction

Unity 2D Destruction
Unity 2D Destruction is a basic tool for breaking 2D sprites into fragments for awesome destruction effects!!! it’s totally free and Open Source so feel free to use it for whatever or contribute to it :smile: If you find this useful or have any questions/requests let me know!

https://github.com/mjholtzem/Unity-2D-Destruction

18 Likes

Nice job

1 Like

Recently made a small update to this so that the source object correctly passes it’s material to the generated fragments and normals are calculated. This allows you to use a diffuse sprite material if you so desire.

Also fixed a bug where it did not work correctly when sprites had custom pivots

3 Likes

awesome! just came across this one as well, which should play nicely with some 2d Destruction: Unity Collider2D Optimization by Alchem

Plzzz I want help, when I imported the package I got 3 errors in the console in sprite exp-loader. Can you help me??

What were the errors? and what version of Unity are you on?

1 Like

Unity 4
this an image of the error msg in console, how to solve it

can you answer me plzz???

Looks like you probably need to update your Unity version

1 Like

This is great !

I was going to do the same thing before finding solution on the net.
You should make it into UNITY Asset store package.

Anyway, unity should add this to their source code too ! :smile:

1 Like

It’s cool, but I have two questions need your suggestions if possible. :slight_smile:

The first is I use some object pooling mechanism to improve the performance, and do you have any suggestion about how can I apply your 2D Destruction package with the object pooling mechanism ?

The second is I want to blow my sprite objects in the air and let it become pieces and spray out with 360 degree. In a short word is that there is no gravity down ground on my game objects.

Sorry for my bad english, and you just done a great job !

Thank you in advanced.

Hey,
Very good asset I like it a lot.
But I have one Problem if i generate the pieces via your script and try to make a Prefab out of these pieces, it can’t save the meshfilter/meshrenderer because its created in your script…

Do you have any workaround that I can save the Sprite with the fragments as prefab.

Thanks for your reply!

I think I replied to an email from you the other day, but maybe it didn’t go through (or maybe it was someone else asking the same question). At any rate here was the response I gave

I think the way to get that to work would be to save the mesh created in the script as an actual mesh asset in your project using AssetDatabase.CreateAsset (https://docs.unity3d.com/ScriptReference/AssetDatabase.CreateAsset.html). Obviously you would want to be discerning about which objects you do this for since you could potentially end up with a large number of tiny mesh objects in your project.

The altenative would be to save the vert/uv data in serialized fields and then re-create the procedural meshes in OnStart or something. Obviously this would have some sort of performance cost, but no where near as high as the initial calculation and creation of all the fragments.

I’d probably go with option A though.

2 Likes

Sorry never got around to replying to this one.
Pooling:
Are you doing the fragmentation at runtime? If so then yes you could probably implement pooling for the spawning of the fragments themselves without too much modification of the package, but in it’s current state the actual calculations of the fragmentation might still cause lag depending on their complexity.

If your doing the fragmentation before-hand I don’t see how pooling would help, since no objects are being instantiated/destroyed, they are just being activated.

Gravity:
should be able to just set use gravity to false on the fragment rigidbodies

1 Like

Hi! Good job!
I wish to ask - and it is possible to create spriteRenderer pieces, instead of meshFilter+meshRenderer?
It would be simple to apply fine all cycle repeatedly to a separate piece of an initial rock… Or to make smooth disappearance of pieces after explosion…
Thanks.
(Forgive for my English.)

Unfortunately, unless I am mistaken, there is no way to control the Mesh of a SpriteRenderer, so it is not possible to replace the meshRenderer with a SpriteRenderer.

That being said you should still be able to make pieces fade out (smooth disappearance) by changing the material properties

Not sure what “apply fine all cycle repeatedly to a separate piece of an initial rock” means

1 Like

hmm, sorry my language…
I meant that having received after the first cutting a piece, to have possibility to cut it once again already as independent “the initial object”

Ok so you want to explode the pieces resulting from the first explosion. There is a script that does that in the Demo folder called ExplodableFragments.cs

Just attach that to your original object when you generate your fragments

1 Like

Fine! Thanks. I was inattentive. Has thought that for a slice it is necessary to repeat simply the main sequence of operations (as with the initial sprite)…
Good luck to you!!

Nice package dude ! Thanks !

It would deserve a few more functionalities though :wink:

Like being able to define the “explosion” force if we want the fragments to have an impulse to emulate an “explosion” type of effect.Also it would be could to have an option to destroy the fragments after some seconds !

1 Like