Is it better to split VFX graphs into multiple instances?

No, just per switch operator.

Thanks! Apologies if you’ve already thought of this, but are you activating the effect through an event via script? If so, lots of the things you are setting can be set directly via script to avoid you having to do the many switches in your graph, something like this (untested code :stuck_out_tongue: ) :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.VFX;

public class VFXEventAttributeExample : MonoBehaviour
{
    VisualEffect visualEffect;
    VFXEventAttribute eventAttribute;
    private int weaponID;

    static readonly int eventID = Shader.PropertyToID("SwordAttack");
    static readonly int positionID = Shader.PropertyToID("position");
    static readonly int colorID = Shader.PropertyToID("color");

    void Start()
    {
        visualEffect = GetComponent<VisualEffect>();    
        eventAttribute = visualEffect.CreateVFXEventAttribute();
    }

    void StartTrail()
    {
        // Set attributes for each weapon
        switch (weaponID)
        {
            case 0:
                eventAttribute.SetVector3(positionID, new Vector3(0f, 0f, 0f));
                eventAttribute.SetVector3(colorID, new Vector3(1f, 0f, 0f));
                break;

            case 1:
                eventAttribute.SetVector3(positionID, new Vector3(0f, 1f, 0f));
                eventAttribute.SetVector3(colorID, new Vector3(0.5f, 1f, 0.5f));
                break;
        }
   
        // Sends the event with the attributes over to be inherited
        visualEffect.SendEvent(eventID, eventAttribute);
    }
}

Then in your VFX you inherit them without the need for using Switches:

Kinda, but if you just need to toggle between a few outputs and there are not a humongous amount of particles, you can do something like this:

(turning off particles per output, only 1 output will show at a time)

If your output(s) are outputting lots of vertices, you can make this more efficient by enabling Compute Culling in the inspector when selecting the desired output:

I noticed in your screenshot you are setting Age manually in Initialize to 0, probably left from prototyping, but don’t think it’s necessary.

Anywho, not sure if any of this would be useful, but hopefully some food for thought :slight_smile:

7044025--835132--YP2Qs26y8Q.gif
7044025--835150--upload_2021-4-15_18-56-8.png
7044025--835162--4jHyvjbfBw.gif
7044025--835168--upload_2021-4-15_19-3-7.png
7044025--835171--upload_2021-4-15_19-8-6.png

4 Likes