Destructible Object in Unity

Zac Bogner
3 min readMar 18, 2024

This article will be fun, because we are going to create a destructible object simulation.

To start, we will need to make a original object and a prefab instance of the same object. SolidDemo will be our main cube.

On the SolidDemo object we will attach a Box collider, Rigidbody and the Demo Object script in which we will make a duplicate of this object and attach the prefab into the prefab reference.

We will create a prefab, and include a matrix of the same object type, cube mesh.

We will disable the mesh renderer of the parent mesh.

Under each cube mesh instance we will add a Mesh collider, marked as convex, and also add a Rigidbody to each object.

We will create a script called Demo Object and attach it to our Solid Object. This be be our instantiated object reference.

  • Check for user input, example Space Key.
  • Create Smoke & Mirror effect.
  • Cast GameObject to our Instantiated fractal object.
  • Get all children rigidbodies as an array.
  • Check for rigidbodies length is > greater than 0.
  • Step through a for each loop containing a referenced variable to the rigidbodies.
  • Add an Explosion Force of a rate * fixedDeltaTime at position and radius.
  • Add Force at Position at Vector One (X, Y, and Z = 1 unit) so the exposition is emitted outwards and up at current transform position.
  • Set detect collisions to true since Rigidbody physics are applied with the convex mesh colliders.

We then want to create another script, and attach this script to all children cube meshes to apply gravity to all children objects. The object will destroy after this condition is met.

And this is how we make a modular destructible system to use for objects such as crates, buildings, doors, etc.

--

--

Zac Bogner

Game Designer and Level Designer, formerly with Rainbow Studios. Focused in Unreal Engine with experience in Unity. Former Race Car Driver.