Q: How do you set a Position property on VisualEffect? A: With an undocumented property name!

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…
  • ???

What you have right now is busted :stuck_out_tongue:

Hello,

I acknowledge the lack of appropriate documentation about this subtlety, even this detailed page doesn’t help.

There are two methods which can help you figure out what is the actual exposed property names:

  • In script, using VisualEffectAsset.GetExposedProperties, you can retrieve the list of all exposed properties, their type and name.
  • In the editor, using the inspector debug, once you modify a property, you can inspect the key used in VisualEffet component serialization.

_debug_view

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);

_switch_space

Also, since the 2023 cycle, the property binder helper can handle automatic conversion for you:

_space_automatic

Thanks for your feedback, I hope these additional informations will help you.

1 Like