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.
pivotX = _Pivot.x;
pivotY = _Pivot.y;
So for your script to work you need to set all the Vector required components as Float.
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.
There might be a better solution to directly set those variadic attributes as Vector3 or Vector2. Iâll ask the VFX team.
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.
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:
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â?
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