Names for "scale" and "angle"?

int Scale = Shader.PropertyToID("scale");
int Angle= Shader.PropertyToID("angle");

VFXEventAttribute.SetVector3(Scale, myVector);
VFXEventAttribute.SetVector3(Angle, myVector);

Both lines do not work with SendEvent(). Please provide me with propper names for these variables.

Morning. scale, angle, pivot, and angularVelocity are what we call variadic attributes. To put it simply, these attributes can be a scalar or a vector of different dimensions depending on the components you require. This is useful to reduce the memory footprint of particles, as it’s pretty common to only require to scale or rotate on one or two axes.

With the additional debug info turned on if we take a look at the computed source code in the inspector when selecting a Set Attribute block, we can see that for variadic attributes, each components are set as floats:

Here is an example with the Pivot attribute where only the XY elements are set.
9916329--1433634--upload_2024-6-30_13-59-18.png
9916329--1433631--upload_2024-6-30_13-59-0.png

pivotX = _Pivot.x;
pivotY = _Pivot.y;

So for your script to work you need to set all the Vector required components as Float.

9916329--1433637--upload_2024-6-30_14-4-33.png

using UnityEngine.VFX;
using UnityEngine;

public class VFX_Evts : MonoBehaviour
{
    public VisualEffect m_VisualEffect;
    private int m_scaleXID;
    private int m_scaleYID;
    private int m_scaleZID;
    private int m_EventNameID;

    void Start()
    {
        m_scaleXID = Shader.PropertyToID("scaleX");
        m_scaleYID = Shader.PropertyToID("scaleY");
        m_scaleZID = Shader.PropertyToID("scaleZ");
        m_EventNameID = Shader.PropertyToID("Fire");
       
        InvokeRepeating("vfxSendEvt", 0.1f, 2.0f);


    }
    void vfxSendEvt()
    {
        var eventAtt = m_VisualEffect.CreateVFXEventAttribute();
        var scale = new Vector3(0.2f, 1.0f, 0.35f);
        eventAtt.SetFloat(m_scaleXID, scale.x);
        eventAtt.SetFloat(m_scaleYID, scale.y);
        eventAtt.SetFloat(m_scaleZID, scale.z);
        m_VisualEffect.SendEvent(m_EventNameID, eventAtt);
    }
}

With this done don’t forget to Inherit the attribute value from Source in the initialize Context to get the data from the Event.

9916329--1433640--upload_2024-6-30_14-7-19.png

There might be a better solution to directly set those variadic attributes as Vector3 or Vector2. I’ll ask the VFX team.

Wish you a sunny day.

4 Likes

Thanks for a very detailed response!

Glad that the post was helpful. @PaulDemeulenaere mentioned to me this morning the existence of the method:
HasVector3, or HasVector2, etc… Those methods can be used to check if an attribute is stored as a particular type.

Furthermore, you can simplify the scripting part by setting custom attributes instead of the built-in.
Let’s say you’re dealing with particle meshes and you need a Vector3 “Scale”. Instead of setting each component independently as I showed in my previous post ( SetFloat(int nameID, float f)), you could just set a Custom attribute of type vector3.

using UnityEngine.VFX;
using UnityEngine;

public class VFX_Evts : MonoBehaviour
{
    public VisualEffect m_VisualEffect;
    private int m_myScaleID;
    private int m_EventNameID;

    void Start()
    {
        m_myScaleID = Shader.PropertyToID("myScale");
        m_EventNameID = Shader.PropertyToID("Fire");
      
        InvokeRepeating("vfxSendEvt", 0.1f, 2.0f);


    }
    void vfxSendEvt()
    {
        var eventAtt = m_VisualEffect.CreateVFXEventAttribute();
        var scale = new Vector3(0.2f, 1.0f, 0.35f);
        eventAtt.SetVector3(m_myScaleID, scale);
        m_VisualEffect.SendEvent(m_EventNameID, eventAtt);
    }
}

Now in your Graph, you just need to be sure to get this CustomAttributes Source value in the Initialize Context and directly set your Built-in variadic attribute with it.

9917367--1433820--upload_2024-7-1_9-47-14.png

That’s it.

3 Likes

Damn, this is really awesome, thanks!

1 Like

Hi @OrsonFavrel - thanks for the info! I was an issue with checking for and setting scale attribute today and noticed in the system inspector these are indeed consumed in the graph as scaleX, scaleY, and scaleZ - if possible it would be great to get this information added to the documentation as it feels pretty essential to know.

A couple of questions around this:

  1. Are there plans to make dealing with these in the future more straightforward? ie, using HasVector3(scaleId), GetVector3(scaleId), and SetVector3(scaleId) to ‘just work’?
  2. In the meantime, I think wrapping these in a custom ‘VariadicVector3’ class may make the most sense for our own use case. Is there an exhaustive list of these for the built-in attributes that I can account for? (including for Vector2, Vectpr4, or other cases where this might pop up).

Also, cheers on the ‘additional debug info’ setting - I had no idea it was there and it will definitely make working this these easier in the future :smiley: