using Unity.Mathematics;
using UnityEngine;
using UnityEngine.VFX;
namespace Game.VFXR {
[VFXType(VFXTypeAttribute.Usage.GraphicsBuffer), StructLayout(LayoutKind.Sequential)]
public struct VFXRSpriteData {
public float3 Pos;
...
}
}
Trying to compile this gives the following error:
Error while processing VFXType
The type Unity.Mathematics.float3 doesn't use the expected [VFXType] attribute.
The field 'Pos' (Unity.Mathematics.float3) in type 'Game.VFXR.VFXRSpriteData' isn't valid.
Does that mean that the new and shiny Visual Effect Graph cannot use the new and shiny Unity.Mathematics types, and we are forced to use the old Vector3 and friends? With all the boxing involved if everything else is float3?
Hello! You are right, this is an oversight from our side. As VFX Graph package has no dependency on mathematics, it was not considered. But I don’t see any technical limitation that would prevent us to support mathematics types. Would you mind filing an issue so that it can be tracked and processed faster on our side?
Yes there’s little chance this is adressed before we have an actual dependency on Unity.Mathematics (which should happen at some point).
Now I guess there’s a workaround:
You can try to duplicate your struct and have one just to bind it to VFX Graph so that it knows what the fields semantics are (in this case a 3 component float vector). As the layout matches those two structs can be aliased without issue.
In your C# code, you use only your struct with the actual Mathematics types, and you just declare the VFX alias struct with “standard” types instead and [VFXType] attribute so that it’s visible in the graph and can be used with SampleBuffer operator for instance.
Note that this has absolutely no runtime performance incidence, it’s only declarative.
More globally, as long as the stride matches, you can reinterpret data from GraphicsBuffer as you want really.