I like using Position properties because the widget in the scene view is useful, but when I try to set the value in a script via SetVector3, I get an error saying “Value of name ‘my var name’ was not found.”
I understand that Positions are not quite as simple as a Vector3 because they also contain info about whether it’s local or world space, but I can’t find any documentation explaining how to set one of these properties via script.
Anyway, on a hunch and because I once came across another undocumented Unity thing long ago that did this, I tried SetVector3(“myVarName_position”, somePosition) and it worked.
Not entirely sure how you would set the space because presumably it uses an enum or something.
Anyway, I think there are a number of ways this could be improved:
Document how to do this with the concatenated string.
Create a SetPosition method on VisualEffect that takes a Vector3 and some kind of enum to set what kind of coordinate space it’s in.
Let SetVector3 gracefully set the position of a Position property… it’s not like there can be a name clash…
In the editor, using the inspector debug, once you modify a property, you can inspect the key used in VisualEffet component serialization.
We have the initiative of creating helpers to ease the binding of composed objects (like Sphere, mainly listed in VFXTypes which can also be extended in the user projects) and/or a synonym mechanisms for simple encapsulation like Position but I can’t provide any ETA.
The space of exposed properties is read-only in runtime, it cannot be modified dynamically because it would affect the graph topology and potentially the generated HLSL.
However, you can ask for the expected space of an exposed property using VisualEffectAsset.GetExposedSpace and it’s always modifiable in VisualEffectAsset:
static readonly int kPositionId = Shader.PropertyToID("myPosition_position");
(...)
var space = component.visualEffectAsset.GetExposedSpace(kPositionId);
if (space == VFXSpace.Local)
{
inputPosition = transform.worldToLocalMatrix * inputPosition;
}
component.SetVector3(kPositionId, inputPosition);
Also, since the 2023 cycle, the property binder helper can handle automatic conversion for you:
Thanks for your feedback, I hope these additional informations will help you.