Output Event Handlers
A VFXOutputEventAbstractHandler is an API helper that hooks into an Output Event to allow you to execute scripts based on the event.
The Visual Effect Graph includes a set of example scripts as a sample. For information on how to install the sample, see Installing sample scripts.
Output Event Handler API
To create your own output event handler, write a script that extends the UnityEngine.VFX.Utility.VFXOutputEventAbstractHandler
class.
When you write a MonoBehaviour that extends this class, it reduces the amount of code required to perform a hook. This is because the base class does the job of filtering the event and calls the following method :
override void OnVFXOutputEvent(VFXEventAttribute eventAttribute)
When you implement this method, Unity calls it every time the event triggers and passes in the event's attributes.
Example
The following example teleports a Game Object to the Given position when it receives an event.
[RequireComponent(typeof(VisualEffect))]
public class VFXOutputEventTeleportObject : VFXOutputEventAbstractHandler
{
public Transform target;
static readonly int kPosition = Shader.PropertyToID("position");
public override void OnVFXOutputEvent(VFXEventAttribute eventAttribute)
{
if(target != null)
target.position = eventAttribute.GetVector3(kPosition);
}
}
Installing Sample Scripts
To help you create your own VFXOutputEventAbstractHandler, the Visual Effect Graph package includes a set of example scripts that you can install via the Package Manager. To do this, select the Visual Effect Graph package then, next to OutputEvent Helpers Sample, click the Import button.
Using Output Event Helpers
The OutputEvent Helper scripts are deployed into the project as a Sample contained in the folder : Assets/Samples/Visual Effect Graph/(version)/OutputEvent Helpers/
.
These helpers are MonoBehaviour Scripts that you can add to Game Objects that hold a VisualEffect Component. These scripts will listen for OutputEvents of a given name, and will react to these events by performing various actions.
Some of these scripts can be safely previewed in editor, while other aren't. The Inspector shall display a Execute in Editor toggle if the script is able to be previewed. Otherwise, you can press the Play button to experience the behavior in play mode.
The Sample Output Event Helpers are the following:
- VFXOutputEventCMCameraShake : Upon receiving a given OutputEvent, Triggers a Camera Shake through the Cinemachine Impulse Sources system.
- VFXOutputEventPlayAudio : Upon receiving a given OutputEvent, Plays a sound f