Search Unity

Cannot access exposed Visual Effect tansform property in code

Discussion in 'Visual Effect Graph' started by fra3point, Feb 14, 2020.

  1. fra3point

    fra3point

    Joined:
    Aug 20, 2012
    Posts:
    198
    Good morning,

    I'm working on an interactive effect using VFX Graph which is based on the position of an exposed transform property.

    upload_2020-2-14_10-21-20.png

    upload_2020-2-14_10-22-32.png

    As you can see in the images above, I'm able to change the transform values in the inspector (and when I do this everything works great), but I can't find a way to access this property from code. The VisualEffect class has methods like SetFloat, SetVector3, etc. but hasn't "SetTransform".

    My current workaround is to use a bunch Vector3 in the graph and then set them via SetVector3 in Update instead of just using a transform, but sincerely I don't like this solution.

    Has anyone succeded accessing a VisualEffect transform property from code?




    Thanks in advance,
    Francesco
     
  2. ThomasVFX

    ThomasVFX

    Unity Technologies

    Joined:
    Jan 14, 2016
    Posts:
    32
    Hello!
    Currently, the exposed properties of more complex types (such as transform) can only be accessed using separate components of lower-level type. Which means that you can set separately its position, angles and scale.

    for your example you will be able to access these 3 properties using SetVector(). The nomenclatured names for all three sub-property names is the following:

    TRANSFORM_position
    TRANSFORM_angles
    TRANSFORM_scale

    If you need more information about performing these efficiently, I invite you to take a look at the code we used in our Transform Property Binder :
    https://github.com/Unity-Technologi...yBinding/Implementation/VFXTransformBinder.cs

    The code makes use of ExposedProperty : an utility class that caches the optimized integer value that you often compute using (Shader.PropertyToID()) to set the properties.
     
    fra3point likes this.
  3. fra3point

    fra3point

    Joined:
    Aug 20, 2012
    Posts:
    198

    Thank you for this answer!

    The VFXPropertyBinder class is a great solution for the moment as it allows us to not write custom companion scripts for every effect.
    I'd expect complex properties to be exposed in the VisualEffect property inspector in the future, but it's fine for now.
     
unityunity