Summer of Code: Progress of Detonator framework

This blog post is written by Ben Throop who is working on a Detonator framework to generate great-looking explosions in Unity games. The project is one of four selected projects that were selected for the Unity Summer of Code.

We’re just 9 days away from the August 31 deadline so it’s time for an update. I’ve been working on Detonator, which is a parametric explosion system. It’s supposed to make getting nice, scalable explosions into your game really easy while at the same time providing a framework for more complex effects.

The good news is that it’s almost done, and that means a ton of changes since the first concept Unity players that I posted on my blog. The main effort has been towards making Detonator entirely code driven. This involved creating a new particle component (DetonatorBurstEmitter) that calls some of the scriptable functions on the standard Unity particle system, but makes one shot emissions and the other sort of scaling effects easier to create. The Unity particle system is surprisingly powerful and is similar to the rest of Unity… if there’s something you can’t do through the UI, you likely can through scripting.

So, what about actually using it? The simplest use case is to take a GameObject, attach a Detonator component to it (in code or in the Inspector), and either call Explode() in code or check the “Explode on Start” checkbox in the Inspector. That will do a whole bunch of stuff… create all kinds of emitters, a light, a force, all corresponding default materials, and then BOOM, you’re exploding. That usage case was a primary design goal and it’s met.

If you want to take it one step further, you can tweak parameters on the Detonator component. The default explosion has a 10m radius, and that can be changed to whatever you’d like – all effects scale accordingly. As anyone that works with particle systems knows, this is not a trivial thing because it needs to change particle size, emitter radius, velocity, emitter position, and forces all in unison.

Performance scalability is also a concern with effects, because, well, they can scale. For that there’s the detail parameter, which affects the number of particles spawned, and even whether or not certain entire sub-components get created. Each piece has a detailThreshold parameter that lets you customize how your Detonator explosion scales to different performance specs. I’ll be looking into how this will hook into the global Unity quality settings as well – no promises for release but I’ll get it in shortly after if it doesn’t make it then.

After detail there’s color. Changing the color of the main Detonator component will have differing effect depending on its alpha value. Since using alpha purely for transparency didn’t make a lot of sense in this context, it instead serves as the color influence. So if you make your color Blue with 50% alpha, then colors of all sub-components will be 50% blended to that blue. Since the normal fireball is orange and other parts are white, this gives a nice non-uniform coloration. If you’d like to go for a stylized look, crank the alpha to 100%.

Duration can also be adjusted. This was tricky because just altering this naively made the explosions really dim, so the alpha values of all the emitters’ color animations try to stay more opaque when the duration is shorter. Everything is tuned to make changing parameters make sense. Of course, we’ll learn a ton more when people are using this en masse, but I’ve given it my best shot to start with.

So that is the main Detonator component. Many people will just use that, but underneath is a full-fledged explosion construction kit. For instance, DetonatorFireball is one of the sub components that a Detonator normally auto-creates. Instead, you can make your own by dragging a DetonatorFireball script onto that same GameObject. You can add one, two, or ten of these and then get busy changing their relative positions, sizes, colors. You can even time when they go off (with randomness) to create startling layered effects. Then add some sparks, smoke, a glow, a light, or whatever you want. In just a few minutes I was able to make a pretty nice mushroom cloud. I can’t want to see what people do with this.

And for the artists out there like myself, you can switch out the materials and textures that your Detonator components use. Either replace them at the top level and let them cascade down to subcomponents, or replace them piece by piece, it’s up to you. I’d really like to see what is possible with stylized or toon explosions with this system.

So what needs to still be done? I still need to reimplement a few components that were in the concept effect… namely the chunk emitter (which sprays any gameobject you’d like with trailing smoke) and the physics force (which acts on rigidbodies and even sets them on fire if you want). The UI of the main Detonator could use some spicing up, but that would mean reimplementing material slots through the drag and drop API, which might not be worth it at this stage. The main thing the UI would do is put buttons in to create each subcomponent so one wouldn’t need to manually drag scripts onto it. It feels like that would add a nice level of polish so I’ll have a look.

If you’d like to follow along more closely and see past progress, including a Unity player with the concept effect, check my site at http://variancetheory.com.

Comments (11)

Calling Explode() in a script didn’t work. Unity didn’t recognize what it meant. I wouldn’t know why, but I’lll poke around in the forums to see if there is anything there. :-(

Efraim

November 1, 2009 at 8:56 pm /

After Effects… meet Unity! ;-)

tau

August 26, 2009 at 1:52 am /

Looks awesome! I wonder how the variety of the explosions can be setup?

Also, what is ETA and form of the release? Will it be a part of Unity (in 2.6? ;)) ?

Martin Schultz

August 24, 2009 at 9:23 pm /

Ah cool, thanks Jonas!

jonas

August 24, 2009 at 8:25 pm /

@Martin: No, all parts of the Detonator Toolkit are scripted on top of Unity 2.5. No internal changes are needed.

Martin Schultz

August 24, 2009 at 7:27 pm /

@Jens: I’m ready to put it into Hard Rock Racing for the Unity Awards! :-)

@Ben: Does mean it’s a new component that it requires a new Unity version? Is it a component like a rigidbody or a mesh, so an internal new component?

Ashkan

August 24, 2009 at 6:18 pm /

awsome
HDR rendering? yes yes!!!

Jens Fursund

August 24, 2009 at 1:35 pm /

I went to your site to try out your different webplayers. I must say; this looks totally awesome, you should really make it easier to find them on your site. I can’t wait to someone integrates these explosions into some content!

Raymond L.

August 24, 2009 at 1:23 pm /

Wahoo! Very cool.
As I remember, there was a problem with the “explosion” in my standard assets.
I had set up several of them and I wanted one of them to be smoke, not fire, but when I changed the texture, all of them changed!
I not only love Detonator, I think it might not have that problem. Also, detonating explosions from scripts opens millions of possibilities. ;-)

ranza

August 24, 2009 at 11:28 am /

Wow! That looks really awesome! Now all we need is a simple HDR effect after the ‘boom’ and Unity will be unbeatable :)