Visual Effect Graph Sample Content
The Visual Effect Graph comes with a set of samples to help you get started.
A sample is a set of assets that you can import into your project and use as a base to build upon or learn how to use a feature. The Visual Effect Graph also includes some helpful Nodes
To find these samples, first install the Visual Effect Graph then:
Go to Windows > Package Manager.
From the Package list view, select Visual Effect Graph. If it is not there:
- From the Packages drop-down menu, select Unity Registry or In Project.
- Go to Edit > Project Settings > Package Manager
- In the Advanced Settings drop-down, enable Show Dependencies. Visual Effect Graph should now appear in the Packages list view.
In the main window that shows the package's details, find the Samples section.
To import a sample into your project, click Import. This creates a Samples folder in your project and imports the sample you selected into it. This is also where Unity imports any future samples into.
Output Event Handlers
This sample includes helper MonoBehaviour Scripts which you can attach to GameObjects that have a VisualEffect component. These scripts listen for Output Events of a given name and react by performing various actions. Some of the scripts support previews in the Editor and some do not. For those that do, the Inspector contains an Execute in Editor toggle. Otherwise, enter Play Mode to view the behavior.
The helper scripts this sample includes are:
- VFXOutputEventCMCameraShake: When it receives an Output Event with the name you specify, this helper script triggers a camera shake through the Cinemachine Impulse Sources system.
- VFXOutputEventPlayAudio: When it receives an Output Event with the name you specify, this helper script plays a sound from an AudioSource
- VFXOutputEventPrefabSpawn: When it receives an Output Event with the name you specify, this helper script spawns an invisible Prefab from a pool of Prefabs. It spawns them at a given position and rotation. It also manages the life of the Prefab based on the Event's lifetime attribute. When the Prefabs spawns, you can use VFXOutputEventPrefabAttributeHandler scripts to configure the Prefab's child elements. For more information, see Using VFXOutputEventPrefabSpawn .
- VFXOutputEventRigidBody: When it receives an Output Event with the name you specify, this helper script applies a force to a RigidBody.
- VFXOutputEventRigidBody: When it receives an Output Event with the name you specify, this helper script triggers a UnityEvent.
Using VFXOutputEventPrefabSpawn
The VFXOutputEventPrefabSpawn MonoBehaviour component spawns Prefabs from a pool. When it instantiates these Prefabs, it makes them invisible. When you enable the component, the component disables (SetActive(false)) each Prefab. Lastly, when you disable the component, the component destroys every Prefab instance. This also occurs when you destroy the GameObject that the component is attached to.
When this component receives an Output Event with the name you specify, it looks for a free (disabled) Prefab, and, if any are available:
- It enables the Prefab.
- If you enable Use Position, it sets the Prefab's position using the position attribute.
- If you enable Use Rotation, it sets the Prefab's rotation from the angle attribute.
- If you enable Use Scale, it sets the Prefab's scale from the scale attribute.
- If you enable Use Lifetime, it starts a Coroutine with a delay based on the lifetime attribute, that disables (frees) the Prefab after the delay. This makes it available to spawn during a future OutputEvent.
- It searches the Prefab instance for any
VFXOutputEventPrefabAttributeHandler
scripts and invokes each one to perform attribute binding.
VFXOutputEventPrefabAttributeHandler
scripts configure parts of the Prefab based on the event that spawned the Prefab. This sample contains two example VFXOutputEventPrefabAttributeHandler
scripts:
- VFXOutputEventPrefabAttributeHandler_Light: When the Prefab spawns, this sets the color and the brightness of the attached Light component based on the OutputEvent's color attribute and the script's Brightness Scale property respectively.
- VFXOutputEventPrefabAttributeHandler_RigidBodyVelocity: When the Prefab spawns, this sets the velocity for the attached RigidBody based on the OutputEvent's velocity attribute.
Visual Effect Graph Additions
This sample includes assets and example graphs that help you get started with the Visual Effect Graph. For example, this sample includes:
- A set of flipbook textures.
- Example graphs that demonstrate various Nodes.
- Shaders and subgraphs that you can use in your project.
- Sets of textures (licensed under CC0) which you can use for visual effects in your project.
This sample uses these assets and examples to reproduce many Built-in Particle System behaviors. For example, it provides a helper to replicate soft particles and a helper that enables you to sample flipbooks with cuts either linearly, or with motion vectors.