♪ [MUSIC] ♪
[TREVOR] Hi, I'm Trevor Ware.
I'm a staff programmer at Blackbird Interactive,
and I've been working on
for the last four years.
[DAVID] Hi, I am David Perdigón,
and I've been an Effects and Concept Artist
at Blackbird Interactive for the last three years.
[TREVOR] In
that works in a shipyard
for a company that sends you derelict spaceships.
Your job is to strip these ships down
and salvage all the valuable materials within them.
It's an extremely dangerous job,
and there's a ton of ways that you can die.
And when you die, the company clones you,
and throws you back in the yard to repeat the cycle.
[DAVID] Our agenda for this talk will be
to introduce you the VFX Graph Editor
and data-driving the effects in Unity,
to work you through the VFX and code setup,
and to give you a demo of how we work in-engine.
The Visual Effect Graph is a specialized tool
to create complex visual effects in Unity
using an intuitive visual interface.
It allows us, among many other things,
to control each and every one of the parameters of our effects
to change and re-use them in different ways
without having to create brand-new effects for each variation,
saving us time and work.
It is a next-generation tool
inspired by film visual effects software
that allows the artist to create incredible visual effects
for video games without writing any code.
It uses a Node system.
Nodes connect together to perform a series of calculations
that input into blocks,
which in turn define particle properties.
Similar to Unity Shader Graph tool,
though not identical.
The first Node, Spawn,
defines how many particles will be spawned and when.
Initialized particles will define their initial values:
size, speed, direction, lifetime, etc.
Update Particle will control
how the particles behave over time:
color variations, gravity, size variation, etc.
The Output Node will define
how the particles are rendered:
Shader skews, textures, Material properties, etc.
Here we can see one simple example
of one of the multiple particle systems
that we are going to see today.
Many properties of particles can be exposed,
and we can also create our own parameters.
These will depend on the needs of our project.
At
to be able to dynamically resize,
change color or be affected by external forces.
Also, explosion had to change the properties,
depending on the element of causes,
such as electricity or fuel.
In order to do that, I created three different Exposed parameters.
The first one, Size, is a float range
that goes from 1 to 5.
This is because the smallest explosion
in the game is 1 meter, and the biggest one is 5 meters.
Color, a simple color gradient,
and Speed, a simple float by default 0.
These parameters will modify any value of any other Node,
and it is the artist who has control
on each and every one of them.
In this example, we can see how the Size parameter
has spread throughout all the particle systems of our FX,
to modify and change the values of them as needed.
Let's see it more in detail.
In this example, we are going to see
how to modify the size parameter,
change the amount of particles that the effects will have.
Size now is set to "2"
because it is a 2-meter explosion.
We are going to feed that value in our Remap float Node,
where the old range value is 1 to 5.
We are going to set a new range that goes
for this specific particle system,
from 200 to 1,000 particles.
We feed the final value into the spawn Node,
and the final number is automatically calculated
to 400 particles when the effect size is equal to "2".
As you see, the Size value not necessarily
will change the size of the particles,
but any other value that we want,
and with a remap float Node, it is pretty easy.
As you see here, a size 1 explosion
will use the minimum particles that was set, 200,
a size 3 will use a number
automatically calculated by the tool, here 600,
and the size 5 will use the maximum
particle set that was set 1,000 for this spark system.
But let's go a little bit further.
We are going to take the same value,
but before we feed the remap float Node
we are going to subtract "1" from the size value.
Then we will remap the old range from 0 to 30,
and we'll feed it into the same spawn Node.
As you see, the final number is 0.
This means that when explosions are smaller than 2 meters,
the number of particles in this debris particle system will be 0.
Only explosion bigger than 2
will include debris particles in it.
This is a 2-meter explosion.
As we can see, it is pretty simple.
It has only a few fires and small animations
plus the particles that we saw before.
However the 5-meter explosion has more details in it.
Lighter debris particle systems,
but the size parameter can be used
to modify any of the values that we need.
Like here, the same size has been used to modify a Speed,
Lifetime and Size of these particles
that we saw in the first example.
We have two other parameters, Color and Speed,
that control only one aspect of the effect.
Color will change the set color of a live Node
of almost every particle system in the effects.
And the Speed will change the set value in this forced Node
on the majority of the systems.
But we will talk more in detail about these two later.
This is the final result.
As you see, the explosion now can change
not only the size of each of the particles,
but the size of the entire effect
and the number of details on bigger explosions.
At this point, the effect is done and ready for implementation.
But we are not doing only one,
we are doing four different explosions.
We can now repeat the same process and create the other three.
Or we can take advantage of the VFX Graph Editor
and include any variation of the same effect
in the same graph asset.
In order to do that, we need Events.
Events are connected to the spawn Node,
and they will tell the particles when they should be played,
and which one should be played.
In this example, we can see that Event 1
will play the Particles 1,
but the Event 2 will play both Particles 1 and 2.
However, the Event 3 is connected to the Stop bar of this spawn Node.
This event will stop the Particles 2,
but it won't affect the Particles 1.
Let's see a real example of Events in our effect.
I know, it looks complex, but it isn't.
Let's simplify. As you see here,
Fire, FuelX, and Electric explosion events
are connected to the same spark system
that we saw different examples.
These sparks are a common system used by almost any explosion.
But not the Cryo one. Cryo is connected
to a different set of particle system.
Electric explosion is connected to Sparks and Smoke,
two of the common particle systems,
but also it is connected to an exclusive set of particles
created only for the Electric explosion.
Let's see how the final product looks like.
Now I'm going to test the FX.
I have the FX here in the Scene
and the VFX Graph Editor window.
I have all the exposed parameters and the Events right here,
and we can send in this window.
I'm going to start with the Fire explosion.
I'm going to test first the smallest one,
and I'm going to send the Fire Event.
That's looking nice.
I'll try a bigger number, let's say, "3.5".
Looking good, and a bigger one.
That's nice. As you can see, the biggest explosion
has more details in it.
I'll change to the Cryo color.
That side is good, I'll send Cryo, smallest number.
That's cool. Let's try the Electric explosion.
Electric explosions are not bigger than 2 meters.
I won't test it in numbers bigger than 2, but, as you can see,
it spawns some electric arcs
that are exclusive to these effects.
And the last one is the FuelX explosion.
Similar to the Fire one, with a different color set.
Let's try the biggest one.
Super cool.
And right here we have another value
that this Speed adds a force to the effects.
It makes the effect move into a specific direction,
Let's do a bigger number.
You see? Trevor will talk more in detail about this, but...
it's working perfectly.
Cool. That's it. Ready for implementation.
[TREVOR] Now let's dive into the code setup of how
we data drive our explosions.
Here's a quick agenda of what we'll talk about today,
including parameter setup, event setup,
how we store our data, how we spawn the visual effect,
how we set the data on the visual effect,
and finally, how we play that visual effect.
First, let's talk about how we set up
the visual effect parameters in code.
We create unique identifiers
using the names of the exposed parameters
from our Visual Effect Graph.
We do this by calling in Shader.PropertyToID
on the name of the parameter.
In code, we use these unique identifiers,
wherever we would have referenced the name of the parameter,
such as when we're setting Shader values.
Similarly, we create unique identifiers for our events
using the event names from the Visual Effect Graph.
The reason we use these unique identifiers
is because it's more efficient than using the string names
when setting Shader values.
Now let's talk about how we're going to store the data.
I've created this small class that stores a float
for the size of the explosion,
a gradient for the color of the explosion,
and an enum for the type of explosion.
It also stores a reference to the Visual Effect Graph Prefab
that will be spawned when the object explodes.
In Unity, there are several different ways
you could store the data.
For example, it can be stored on a MonoBehaviour on a Prefab
or can be stored in a ScriptableObject.
On
that are referenced by our Prefabs.
The reason for this is that we can reuse those Scriptable Objects
on the Prefabs that share similar characteristics.
And if we ever wanted to change that data,
we don't have to change every Prefab,
just that one ScriptableObject,
and all Prefabs that reference that object
would be updated automatically.
On the right, we have four different examples of our data.
Notice they all reference the same Visual Effect Prefab?
When the object that references this data explodes,
they're all going to spawn the same visual effect,
but because the data that accompanies it is different,
they're all going to look unique.
Now let's talk about how we're going to spawn the visual effect
when an object explodes.
To account for motion, the first thing we'll do
is grab the velocity of the Rigidbody of the object.
Then we need to calculate how we'll orient the explosion.
If the object is in motion, we'll point it
facing the direction of motion
using Quaternion.LookRotation on the velocity.
If it's not moving, we'll just use the object's rotation.
The reason we point the explosion in the direction of motion
is so that all we need to do is pass a float
for speed to the Visual Effect Graph.
This allows David to modify the speed however he likes
to make the particles look the best without needing
to worry about maintaining the directionality of velocity.
This means that we only need to set the Z component
of the velocity vector in force Nodes in our VFX Graph.
Then we'll instantiate the effect
using GameObject.Instantiate
using the Visual Effect Graph Prefab from our data,
the object's position, and the rotation we just calculated.
Once we have the instance of the explosion,
we'll get the Visual Effect Component off of it,
so we can start setting data on it.
The first parameter we'll set is the Size
using the float we defined in our data earlier.
Below are two examples of the same explosion,
one at Size 1 and one at Size 2.
The next parameter we'll set is the Color
using the gradient we defined in our data.
Here are two explosions, one that has a gradient of blue
and one that has a gradient of purple.
Finally, we'll set the Speed parameter.
by taking the magnitude of the velocity
we got from the Rigidbody earlier.
Here is one explosion at 5 meters per second,
and one that's at 15 meters per second.
Lastly, we need to tell the visual effect to play.
We do this by sending an Event
to Visual Effect Graph.
We do a switch statement
on the type of explosion we defined in our data
depending on the explosion type we send
the corresponding event identifier to the Visual Effect Graph.
This leads us into our in-engine demo.
We've created four different data sets
and attached them to four different explosive props in our game.
Here is the first prop, which is a small fire explosive canister.
It uses the Fire explosion type.
The next prop is a medium-sized coolant canister,
and it uses the Cryo explosion type.
Next is a medium-sized electrical junction box,
and it uses the Electric explosion type.
And finally, here is the large fuel canister,
and it uses the FuelX explosion type.
So overall, Unity’s Visual Effect Graph
is a very powerful tool.
It allows us to data-drive our visual effects
by letting us expose parameters,
that can be controlled by our code and our data.
Using events, we can make our effects multi-purposed.
And we can build those effects with variation in mind,
meaning that we can tweak our data to make each effect look different
without needing to create new effects
every time we want to make a small change.
That concludes our presentation.
Thank you for attending this Unite Now session
on data-driven explosions.
We hope you learned a lot.
Please check the Unite Now page for more information.
♪ [MUSIC] ♪