Introduction

Crates that splinter when they're shot, a barrel that bursts, a panel that falls apart when your script says so: Make Breakable cuts a placed model into chunky pieces and wires it up so that, when it breaks, the model disappears and the pieces fly out from where they were, fall and settle as physics debris.

Right-click a ModelReference in the entity list and choose Make Breakable... To cut a model into pieces without wiring anything up, right-click it in the Model Editor and choose Fracture into Debris... (see below).

In game: a stack of cardboard boxes on a pallet, then the moment it breaks with its pieces bursting out, the pieces in the air, and the pieces settled on the floor around where it stood.

Make Breakable

The Make Breakable window for packagingbox_4_01: 6 pieces, cut 11, cut faces Dark inside with the inner skin, mass from size, thrown out at 2.5 m/s, breaks when shot or hit with damage at least 20, pistol and shotgun hits round it, and a preview of the six pieces pushed apart, each in its own colour.

The window cuts the model as you change the settings and shows the pieces pushed apart, each in its own colour with its cut faces darker. Nothing in the level changes until you press Make Breakable.

  • Pieces: how many, 2 to 16. Every piece becomes a live physics body when the model breaks, so a dozen is plenty. A piece that would hold almost nothing (a few stray triangles) is merged into its neighbours, so you can get one or two fewer than you asked for.
  • Cut and Another Way: the same number always cuts the model the same way. Press Another Way until you like the pieces.
  • Cut faces: what the inside looks like. Dark inside paints every cut face with the darkest colour of the model's own texture along that cut: a dark, hollow-looking inside. Texture inside carries the model's texture flat across the cut at the same scale, so solid things (wood, concrete, cardboard) look solid all the way through.
  • Inner skin: most game models have no faces where their parts meet, so some cuts can't be closed. The inner skin is a copy of the surface a few millimetres inside it, drawn in the inside colour, so a piece never shows its hollow inside through a gap.
  • Mass: leave Mass from size ticked to give each piece a mass from its own volume, or untick it and give the weight of all the pieces together.
  • Thrown out at: how fast each piece leaves as it appears, outwards from the model's middle and a little up. 0 lets them just drop.
  • Breaks when shot or hit and its damage: how much one hit has to do. Untick it to break the model only from your script.
  • Also pistol / shotgun hits anywhere round it: also break on a bullet that lands inside the model's bounding sphere.
  • Pieces go after: seconds after the break the pieces are removed again (0 keeps them).

Making it can't be undone in full: the piece models, their collision and their physics are added to the level like an import. The script changes are ordinary undo steps.

What It Makes

Each piece is a physics prop of its own, built the way the game's moving props are (see Physics Props That Move), in a composite Breakables\<name>_Debris\<name>_NN:

  • a ModelReference drawing the piece's own model (in the level's models as DEBRIS\<name>\<name>_NN, with the original's materials on it), marked is_debris as the game's own broken pieces are, and keyed by its body's name so a spawned copy finds it;
  • collision made from the piece's own triangles, ballistic and ghosted until the piece appears, as the game's props have it;
  • a PhysicsSystem with one body: the piece's convex hull, at most 64 corners;
  • a ThinkOnce called Kick that gives it a PhysicsApplyImpulse outwards as it appears.

The model itself goes into a composite of its own, Breakables\<name>, placed where it was (links into it are kept). That composite holds, for every piece, an is_template instance of it placed where the piece sits in the whole model and an AssetSpawner that spawns it, and the break itself: a LogicOnce called BreakOnce. When it fires, the model hides and disables (its collision goes with it, and so does any collision-only partner beside it, such as the game's Collision01_COL), the composite's Broken pin fires, and a tenth of a second later (a LogicDelay called SpawnDelay, so the model's collision is gone first) every spawner spawns its piece. The pieces cost nothing until then.

Save & Build to take it into the game.

Breaking It From Script

The breakable composite has two pins: Break, a method to call, and Broken, which fires once it has broken. Link a trigger, a timer or anything else to Break on its instance, and link Broken to whatever should happen after (an alarm, an objective, a door). It breaks once; calling Break again does nothing.

Shots and hits reach it the way they reach the game's breakable bottles: the model's on_damaged through a WEAPON_DamageFilter with the damage you chose, plus an AreaHitMonitor round it when Also pistol / shotgun hits is ticked. Edit or remove those entities like any others.

Fracture into Debris

In the Model Editor, right-click the model and choose Fracture into Debris.... The same window cuts the model, and Make Debris Pieces makes only the piece composites (Breakables\<model>_Debris), placing nothing. Use them for effects of your own: place an instance of a piece marked is_template, and an AssetSpawner with allow_physics ticked whose asset is linked to that instance spawns the piece when its spawn is called. The piece appears where the template instance is placed, not where the spawner is (the game's own vending machines work the same way). To put a piece back where it was in the whole model, place its template instance at the piece's pivot relative to the model (the AI tool fracture_model reports every pivot).

Limits

  • Only a static model breaks: not a character, not a model that is already a physics prop, not a brush, and not one made only of glass or decals.
  • The pieces are cut from what the model draws up close (its first LOD).
  • Characters walk through physics debris, as they do through all of the game's moving props: debris never blocks anyone.
  • The direction the pieces are thrown is worked out for the model as it is placed. If you place more copies of the breakable at other angles, their pieces are still thrown the first way.
  • A few models with thin walls built from separate parts (some bins) leave a cut face open here and there; the inner skin hides it.
  • Anything else with physics standing where the model stands throws the pieces out hard as they appear. The game's oil barrel, for one, carries a burn effect with a physics body of its own in its middle: take that out of the composite, or break a model without one.

Related

  • Physics Props That Move: how the game's moving props are built
  • Model Editor: Fracture into Debris
  • Scripting: wiring the Break and Broken pins
  • AI assistants: make_breakable does the same as the window (with dry_run to see the cut first, and preview for a picture of the pieces), fracture_model makes the pieces only, and list_breakables lists the level's breakables