### Play Audio on VFX Event with VFXOutputEventPlayAudio Source: https://context7.com/unity-technologies/visualeffectgraph-samples/llms.txt Configure VFXOutputEventPlayAudio in the inspector to play an AudioClip via an AudioSource when a specific VFX output event fires. This example shows scene wiring and a custom C# extension for more complex callbacks using UnityEvent. ```csharp using UnityEngine; using UnityEngine.Events; using UnityEngine.VFX; using UnityEngine.VFX.Utility; [RequireComponent(typeof(VisualEffect))] public class VFXOutputEventUnityEventExample : VFXOutputEventAbstractHandler { public override bool canExecuteInEditor => false; public UnityEvent onEvent; // wire anything in the Inspector public override void OnVFXOutputEvent(VFXEventAttribute eventAttribute) { onEvent?.Invoke(); } } ``` -------------------------------- ### Sample Controller for VFX Graph Samples Source: https://context7.com/unity-technologies/visualeffectgraph-samples/llms.txt Sample scripts subscribe to SampleLoader's onMenuToggle event to pause VFX simulation when the overlay menu is open. Programmatic navigation and keyboard shortcuts are also available. ```csharp using UnityEngine; using UnityEngine.VFX; public class MySampleController : MonoBehaviour { VisualEffect m_VFX; private void OnEnable() { m_VFX = GetComponent(); // Subscribe to the global menu-open event. if (SampleLoader.instance != null) SampleLoader.instance.onMenuToggle += OnMenuToggle; } private void OnDisable() { if (SampleLoader.instance != null) SampleLoader.instance.onMenuToggle -= OnMenuToggle; } private void OnMenuToggle(bool isOpen) { // Pause VFX simulation while the overlay is visible. m_VFX.pause = isOpen; } } // Programmatic navigation (e.g. from a UI button): // SampleLoader.instance.NextScene(); // advance to next scene // SampleLoader.instance.MenuLoadScene(3); // jump to scene index 3 // SampleLoader.instance.SetDemoMode(false); // disable auto-advance // SampleLoader.instance.SetFPSVisible(true); // show FPS counter // Keyboard shortcuts built into SampleLoader: // Escape – toggle navigation menu // F10 – save timestamped screenshot PNG // F11 – toggle demo mode // F12 – toggle FPS counter ``` -------------------------------- ### VFXOutputEventPrefabSpawn: Pooled Prefab Spawner Source: https://context7.com/unity-technologies/visualeffectgraph-samples/llms.txt Manages a pool of prefabs, activating and configuring them based on VFX output events. Requires a VisualEffect component and specific attribute bindings in the VFX Graph. ```csharp using UnityEngine; using UnityEngine.VFX; using UnityEngine.VFX.Utility; [RequireComponent(typeof(ParticleSystem))] public class SetParticleColorFromEvent : VFXOutputEventPrefabAttributeAbstractHandler { static readonly int k_Color = Shader.PropertyToID("color"); public override void OnVFXEventAttribute(VFXEventAttribute attr, VisualEffect vfx) { var raw = attr.GetVector3(k_Color); var ps = GetComponent(); var main = ps.main; main.startColor = new Color(raw.x, raw.y, raw.z); ps.Play(); } } ``` -------------------------------- ### Define Custom Persistent Game Option with ScriptableObject (C#) Source: https://context7.com/unity-technologies/visualeffectgraph-samples/llms.txt Subclass GameOption to create a custom persistent setting, like post-processing quality, which automatically loads at startup and can be accessed globally. Implement Apply() for custom logic. ```csharp using UnityEngine; using GameOptionsUtility; // Define a custom option (e.g. post-processing quality level). [CreateAssetMenu(menuName = "Game Options/Post Processing Option")] public class PostProcessingOption : GameOption { const string k_PrefKey = "GameOptions.PostProcessQuality"; public int quality { get => PlayerPrefs.GetInt(k_PrefKey, 1); set => PlayerPrefs.SetInt(k_PrefKey, value); } public override void Apply() { // Example: toggle a Volume weight based on quality setting. var volume = Object.FindObjectOfType(); if (volume != null) volume.weight = quality > 0 ? 1f : 0f; } } // Read / write from any MonoBehaviour: public class OptionsMenuController : MonoBehaviour { void Start() { var opt = GameOption.Get(); Debug.Log($"Current post-process quality: {opt.quality}"); } public void SetQuality(int level) { var opt = GameOption.Get(); opt.quality = level; GameOptions.Apply(); // re-apply all registered options } } ``` -------------------------------- ### Control PlayableDirector Timeline with MagicLampHandler (C#) Source: https://context7.com/unity-technologies/visualeffectgraph-samples/llms.txt Attach this script to a GameObject with a mesh collider to manually scrub a PlayableDirector timeline based on mouse clicks, revealing or hiding VFX. ```csharp using UnityEngine; using UnityEngine.Playables; // Attach to the lamp mesh collider. // Assign the scene's PlayableDirector (containing VFX control tracks) in the Inspector. public class MagicLampHandler : MonoBehaviour { public PlayableDirector TimelineDirector; float m_Interp = 0f; bool m_Reverse = true; // start hidden; first click reveals void OnMouseDown() => m_Reverse = !m_Reverse; void Update() { float speed = m_Reverse ? -1f : 1f; m_Interp = Mathf.Clamp(m_Interp + Time.deltaTime * speed, 0f, (float)TimelineDirector.duration); // Manual evaluation keeps the timeline at the exact scrub position. TimelineDirector.time = m_Interp; TimelineDirector.Evaluate(); } } ``` -------------------------------- ### Control Light Properties from VFX Event Attributes Source: https://context7.com/unity-technologies/visualeffectgraph-samples/llms.txt VFXOutputEventPrefabAttributeLightHandler allows a spawned Light prefab to react to VFX 'color' attributes. This custom handler extends it to dynamically set light color and intensity, supporting both standard Lights and HDRP lights. ```csharp // Place this component on the root of a Light prefab. // The spawner will call OnVFXEventAttribute immediately after activating the instance. // Attribute expected from the VFX Graph Output Event: // color (Vector3) – linear HDR color; magnitude = intensity using UnityEngine; using UnityEngine.VFX; using UnityEngine.VFX.Utility; #if VFX_OUTPUTEVENT_HDRP_10_0_0_OR_NEWER using UnityEngine.Rendering.HighDefinition; #endif [RequireComponent(typeof(Light))] public class CustomLightEventHandler : VFXOutputEventPrefabAttributeAbstractHandler { public float brightnessScale = 2.0f; // multiply the decoded intensity static readonly int k_Color = Shader.PropertyToID("color"); public override void OnVFXEventAttribute(VFXEventAttribute eventAttribute, VisualEffect visualEffect) { var raw = eventAttribute.GetVector3(k_Color); var intensity = raw.magnitude * brightnessScale; var color = new Color(raw.x, raw.y, raw.z) / raw.magnitude; #if VFX_OUTPUTEVENT_HDRP_10_0_0_OR_NEWER var hd = GetComponent(); hd.SetColor(color); hd.SetIntensity(intensity); #else var light = GetComponent(); light.color = color; light.intensity = intensity; #endif } } ``` -------------------------------- ### Set Initial Rigidbody Velocity on Spawn Source: https://context7.com/unity-technologies/visualeffectgraph-samples/llms.txt Use this handler to set the linear and angular velocity of a Rigidbody prefab when it's spawned by VFXOutputEventPrefabSpawn. Requires the VFX_OUTPUTEVENT_PHYSICS define. ```csharp using UnityEngine; using UnityEngine.VFX; using UnityEngine.VFX.Utility; // Extending the pattern: add angular velocity from a custom "angularVelocity" attribute. [RequireComponent(typeof(Rigidbody))] public class RigidbodyFullVelocityHandler : VFXOutputEventPrefabAbstractHandler { static readonly int k_Velocity = Shader.PropertyToID("velocity"); static readonly int k_AngularVelocity = Shader.PropertyToID("angularVelocity"); public override void OnVFXEventAttribute(VFXEventAttribute attr, VisualEffect vfx) { var rb = GetComponent(); rb.WakeUp(); if (attr.HasVector3(k_Velocity)) rb.linearVelocity = attr.GetVector3(k_Velocity); if (attr.HasVector3(k_AngularVelocity)) rb.angularVelocity = attr.GetVector3(k_AngularVelocity); } } ``` -------------------------------- ### Manage Graphic Settings with Built-in GraphicOption (C#) Source: https://context7.com/unity-technologies/visualeffectgraph-samples/llms.txt Access and modify built-in graphic settings like resolution, fullscreen mode, and VSync using the GraphicOption subclass of GameOption. Call GameOptions.Apply() to persist and apply changes. ```csharp using GameOptionsUtility; // Access anywhere at runtime (no MonoBehaviour needed): public class GraphicsSettingsUI : MonoBehaviour { void ApplyUserSettings(int width, int height, bool fullscreen, bool vsync) { var gfx = GameOption.Get(); gfx.width = width; gfx.height = height; gfx.fullScreenMode = fullscreen ? FullScreenMode.FullScreenWindow : FullScreenMode.Windowed; gfx.vSync = vsync; gfx.quality = QualitySettings.GetQualityLevel(); // Persist and apply all settings immediately. GameOptions.Apply(); // Apply() calls Screen.SetResolution, QualitySettings.vSyncCount, // and Application.targetFrameRate under the hood. } } ``` -------------------------------- ### Apply Anti-Aliasing Settings to HDRP Cameras Source: https://context7.com/unity-technologies/visualeffectgraph-samples/llms.txt Use this script to change anti-aliasing modes for HDRP cameras. Ensure HDRPGameOptionsManagedCamera is added to each camera GameObject. The anti-aliasing mode persists to PlayerPrefs and is applied to all managed cameras. ```csharp // 1. Add HDRPGameOptionsManagedCamera to every camera you want to control. // It auto-registers/unregisters on Enable/Disable. // 2. Change anti-aliasing from a settings UI: using GameOptionsUtility.HDRP; using UnityEngine.Rendering.HighDefinition; public class AASettingsUI : MonoBehaviour { public void SetTAA() => ApplyAA(HDAdditionalCameraData.AntialiasingMode.TemporalAntialiasing); public void SetSMAA() => ApplyAA(HDAdditionalCameraData.AntialiasingMode.SubpixelMorphologicalAntiAliasing); public void SetFXAA() => ApplyAA(HDAdditionalCameraData.AntialiasingMode.FastApproximateAntialiasing); public void SetNone() => ApplyAA(HDAdditionalCameraData.AntialiasingMode.None); void ApplyAA(HDAdditionalCameraData.AntialiasingMode mode) { var opt = GameOption.Get(); opt.antiAliasing = mode; // persists to PlayerPrefs GameOptions.Apply(); // pushes the value to all managed cameras } } ``` -------------------------------- ### Control VFX Parameters in Real-Time with TerrainVFXBinder Source: https://context7.com/unity-technologies/visualeffectgraph-samples/llms.txt This script demonstrates driving multiple VisualEffect exposed properties in real-time using mouse input and UI sliders. It sets Vector2 and float properties every frame. ```csharp using UnityEngine; using UnityEngine.VFX; using UnityEngine.VFX.Utility; // Minimal repro: set three float/Vector2 exposed properties every frame. public class TerrainVFXBinder : MonoBehaviour { public VisualEffect vfx; // ExposedProperty casts implicitly from string to the VFX property ID. public ExposedProperty Position = "Position"; public ExposedProperty WorldSize = "WorldSize"; public ExposedProperty WaterElevation = "Water Elevation"; Vector2 m_pos = Vector2.zero; Vector2 m_size = Vector2.one; void Update() { // Pan with arrow keys m_pos += new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")) * Time.deltaTime; vfx.SetVector2(Position, m_pos); vfx.SetVector2(WorldSize, m_size); vfx.SetFloat (WaterElevation, Mathf.PingPong(Time.time * 0.1f, 1f)); } // Guard: always verify properties exist before setting them. bool Ready() => vfx != null && vfx.HasVector2(Position) && vfx.HasVector2(WorldSize) && vfx.HasFloat(WaterElevation); } ``` -------------------------------- ### Animate VFX Visibility with ARRadarController Source: https://context7.com/unity-technologies/visualeffectgraph-samples/llms.txt This script controls the animated show/hide of a VFX effect by setting a float property 'Initialize' on the VisualEffect component. Attach to a GameObject with a VisualEffect component. ```csharp using UnityEngine; using UnityEngine.VFX; using System.Collections; // Attach to a GameObject that has a VisualEffect component (ARRadar.vfx). public class ARRadarController : MonoBehaviour { public AnimationCurve curve; // ease curve (0→1) public float showSpeed = 0.7f; public float hideSpeed = 1.2f; public bool toggle = true; // true = showing, false = hiding Light m_light; float m_lightIntensity; VisualEffect m_vfx; // Exposes the "Initialize" float property in VFX Graph. static readonly int k_Initialize = Shader.PropertyToID("Initialize"); void Awake() { m_vfx = GetComponent(); m_light = GetComponentInChildren(); if (m_light != null) m_lightIntensity = m_light.intensity; } IEnumerator Start() { float value = 0f; while (true) { value += Time.deltaTime * (toggle ? showSpeed : -hideSpeed) * curve.Evaluate(value); value = Mathf.Clamp01(value); m_vfx.SetFloat(k_Initialize, value); if (m_light != null) m_light.intensity = Mathf.Lerp(0f, m_lightIntensity, value); if (Input.GetKeyDown(KeyCode.Space)) toggle = !toggle; yield return null; } } } ``` -------------------------------- ### VFXOutputEventRigidBody: Physics Force from VFX Events Source: https://context7.com/unity-technologies/visualeffectgraph-samples/llms.txt Applies physics forces (Impulse, Explosion, VelocityChange) to a Rigidbody component based on VFX output event attributes like position, size, and velocity. Requires the VFX_OUTPUTEVENT_PHYSICS define. ```csharp // Setup via Inspector on a GameObject with VisualEffect + VFXOutputEventRigidBody: // rigidBody → assign the Rigidbody to push // eventType → Impulse | Explosion | VelocityChange // attributeSpace → Local | World // The Meteorite sample extends this to drive multiple Rigidbodies simultaneously: using UnityEngine; using UnityEngine.VFX; using UnityEngine.VFX.Utility; [RequireComponent(typeof(VisualEffect))] public class OutputEventHandlerMultipleRB : VFXOutputEventAbstractHandler { public override bool canExecuteInEditor => false; public Rigidbody[] rigidBodies; public float UpwardsModifier = 1.0f; enum RigidBodyEventType { Impulse, Explosion, VelocityChange } public RigidBodyEventType eventType; static readonly int k_Position = Shader.PropertyToID("position"); static readonly int k_Size = Shader.PropertyToID("size"); static readonly int k_Velocity = Shader.PropertyToID("velocity"); public override void OnVFXOutputEvent(VFXEventAttribute eventAttribute) { var position = eventAttribute.GetVector3(k_Position); var size = eventAttribute.GetFloat(k_Size); var velocity = eventAttribute.GetVector3(k_Velocity); foreach (var rb in rigidBodies) { if (rb == null) continue; switch (eventType) { case RigidBodyEventType.Impulse: rb.AddForce(velocity, ForceMode.Impulse); break; case RigidBodyEventType.Explosion: rb.AddExplosionForce(velocity.magnitude, position, size, UpwardsModifier); break; case RigidBodyEventType.VelocityChange: rb.AddForce(velocity, ForceMode.VelocityChange); break; } } } } ``` -------------------------------- ### Flash Emission on VFX Output Event Source: https://context7.com/unity-technologies/visualeffectgraph-samples/llms.txt Custom handler that flashes a renderer's emission color when a VFX output event occurs. It can read an optional color attribute from the event and requires a VisualEffect component. ```csharp using UnityEngine; using UnityEngine.VFX; using UnityEngine.VFX.Utility; // Custom handler: flash a renderer's emission color on every VFX output event. [RequireComponent(typeof(VisualEffect))] public class FlashEmissionOnEvent : VFXOutputEventAbstractHandler { public override bool canExecuteInEditor => false; public Renderer targetRenderer; public Color flashColor = Color.white; public float flashDuration = 0.1f; static readonly int k_Color = Shader.PropertyToID("color"); // VFX attribute public override void OnVFXOutputEvent(VFXEventAttribute eventAttribute) { // Read optional color attribute sent by the VFX graph. if (eventAttribute.HasVector3(k_Color)) { var raw = eventAttribute.GetVector3(k_Color); flashColor = new Color(raw.x, raw.y, raw.z); } if (targetRenderer != null) StartCoroutine(Flash()); } System.Collections.IEnumerator Flash() { var block = new MaterialPropertyBlock(); block.SetColor("_EmissiveColor", flashColor); targetRenderer.SetPropertyBlock(block); yield return new WaitForSeconds(flashDuration); targetRenderer.SetPropertyBlock(null); } } // In the Inspector: set "Output Event" to match the event name inside your VFX Graph asset. ``` -------------------------------- ### Trigger Cinemachine Camera Shake from VFX Event Source: https://context7.com/unity-technologies/visualeffectgraph-samples/llms.txt Use VFXOutputEventCinemachineCameraShake to translate VFX position and velocity attributes into Cinemachine camera shakes. No custom code is needed if configured in the inspector. For manual triggering, this C# script shows how to generate impulses. ```csharp using UnityEngine; #if VFX_OUTPUTEVENT_CINEMACHINE_2_6_0_OR_NEWER using Cinemachine; // or Unity.Cinemachine for 3.x public class ManualShakeTrigger : MonoBehaviour { public CinemachineImpulseSource impulseSource; public void TriggerShake(Vector3 worldPosition, float strength) { impulseSource.GenerateImpulseAt(worldPosition, Vector3.up * strength); } } #endif ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.