Skip to content

Game.Rendering.Utilities.VFXUtils

Assembly: Game (Assembly-CSharp.dll)
Namespace: Game.Rendering.Utilities

Type: public static class

Base: System.Object

Summary:
Utility extension methods for UnityEngine.VFX.VisualEffect that safely set VFX parameter values only if the parameter exists on the effect. Each method checks the corresponding HasX(...) API before calling SetX(...), and returns a boolean indicating whether the set succeeded. These helpers are intended for mod code in Cities: Skylines 2 that manipulates VFX Graph properties without causing unnecessary exceptions or errors when parameters are missing.


Fields

  • None.
    This static utility class declares no instance or static fields.

Properties

  • None.
    No properties are declared.

Constructors

  • None.
    Being a static class, VFXUtils has no public constructors or instance initialization.

Methods

  • public static bool SetCheckedFloat(this VisualEffect effect, int id, float v)
    Checks effect.HasFloat(id); if true sets effect.SetFloat(id, v) and returns true; otherwise returns false. Use to safely set float parameters on a VisualEffect when you are not certain the property exists.

Notes: - id is the integer property identifier (commonly produced via Shader.PropertyToID("PropertyName") or other VFX property id mechanisms). - Does not guard against effect being null — callers should ensure the VisualEffect reference is valid. - Must be called on Unity’s main thread (UnityEngine API).

  • public static bool SetCheckedVector3(this VisualEffect effect, int id, Vector3 v)
    Checks effect.HasVector3(id); if true sets effect.SetVector3(id, v) and returns true; otherwise returns false. Use for Vector3 VFX parameters.

  • public static bool SetCheckedVector4(this VisualEffect effect, int id, Vector4 v)
    Checks effect.HasVector4(id); if true sets effect.SetVector4(id, v) and returns true; otherwise returns false. Use for Vector4 (e.g., color or 4D data) VFX parameters.

  • public static bool SetCheckedTexture(this VisualEffect effect, int id, Texture v)
    Checks effect.HasTexture(id); if true sets effect.SetTexture(id, v) and returns true; otherwise returns false. Use for texture properties exposed by the VFX Graph.

  • public static bool SetCheckedInt(this VisualEffect effect, int id, int v)
    Checks effect.HasInt(id); if true sets effect.SetInt(id, v) and returns true; otherwise returns false. Use for integer VFX parameters.

General remarks for all methods: - These are extension methods; call them as instance-style methods on a VisualEffect reference. - They are small convenience wrappers to avoid repeatedly writing HasX checks throughout mod code. - Prefer caching the integer property id (via Shader.PropertyToID or similar) rather than calling string->id conversions repeatedly for performance. - If you need to react when a property is missing, the boolean return value lets you provide a fallback or log a warning.

Usage Example

using UnityEngine;
using UnityEngine.VFX;

// cache ids once (e.g. static readonly)
int intensityId = Shader.PropertyToID("Intensity");
int colorId = Shader.PropertyToID("TintColor");
int mainTexId = Shader.PropertyToID("MainTex");

VisualEffect vfx = GetComponent<VisualEffect>();
if (vfx != null)
{
    // Set a float if the VFX exposes it
    if (!vfx.SetCheckedFloat(intensityId, 1.5f))
    {
        // fallback or log: the effect does not have "Intensity"
        Debug.Log("VFX missing 'Intensity' property");
    }

    // Set a Vector4 (e.g., color) and a texture safely
    vfx.SetCheckedVector4(colorId, new Vector4(1f, 0.8f, 0.6f, 1f));
    if (!vfx.SetCheckedTexture(mainTexId, someTexture))
    {
        // handle missing texture property
    }
}