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:
    269
    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
     
    skoteskote and Orion_games_ltd like this.
  2. ThomasVFX

    ThomasVFX

    Joined:
    Jan 14, 2016
    Posts:
    45
    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.
     
    worldofvrgmbh, pahe and fra3point like this.
  3. fra3point

    fra3point

    Joined:
    Aug 20, 2012
    Posts:
    269

    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.
     
  4. magehuntz

    magehuntz

    Joined:
    Mar 24, 2017
    Posts:
    27
    Please put this information on the documentation. I was struggling to access those properties in my project and could only find this information here.
     
  5. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,073
  6. dyburke

    dyburke

    Joined:
    Nov 11, 2012
    Posts:
    15
    This seems to be the current location: https://github.com/Unity-Technologi...yBinding/Implementation/VFXTransformBinder.cs

    Still can't figure out how to get the Property Binder to properly work with Transform though. I realize that's not quite what this thread is about, but I'm searching for why my Property Binder says
    upload_2022-2-21_10-22-15.png
    There needs to be more substance to this error to let me know what the issue is; seems like a very simple use case, but I've been trying as many secret "_suffix" magic words I can find and it's unable to bind the transform.
     
  7. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hi @dyburke ,
    Can you confirm that you've assigned a target and that your Property name matches that of an exposed Transform property?

    If all of that's good, try renaming your property or removing/re-adding the property binder in question.
     

    Attached Files:

    plehannowww likes this.
  8. dyburke

    dyburke

    Joined:
    Nov 11, 2012
    Posts:
    15
    @VladVNeykov The dropdown you show next to the 'Property' field wouldn't even pop up. I tried a lot of rename and reassigning. In the end, it was removing the entire Mono component and re-adding it that worked; the dropdown you show now has my property in it. I'm not sure what caused the issue; I've been unable to reproduce it.
     
  9. Liderangel

    Liderangel

    Joined:
    Jul 8, 2018
    Posts:
    101

    I'm trying to do the exact same thing as in your GIF but leaving the Target empty so that it can be assigned through script, but I can't find any documentation on how to do this. The help would be much appreciated!
     
  10. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hey @Liderangel ,

    If you are setting the transform via script, you can just set it directly and not use the binders at all.
    You can look for the VFXTransformBinder script in your packages to see how the binder component does it, but in a nutshell, expose your transform in blackboard, and then set separately the position, angle, and scale.

    Pseudo-example:
    Say your exposed transform is named myTransform:

    Code (CSharp):
    1. Transform player; // the transform you want to track
    2. VisualEffect vfx; // your vfx component
    3.  
    4. void Update()
    5. {
    6.    vfx.SetVector3("myTransform_position", player.position);
    7.    vfx.SetVector3("myTransform_angles", player.eulerAngles);
    8.    vfx.SetVector3("myTransform_scale", player.localScale);
    9. }
    Hope this helps!
     
    Liderangel and ashtorak like this.
  11. ashtorak

    ashtorak

    Joined:
    Feb 19, 2014
    Posts:
    53
    @VladVNeykov
    Thanks, these examples help a lot!
    At first I was looking for a way to convert a Vector3 into a transform position inside the graph, but it doesn't seem possible? Even though the greyed out position fields show the values up to the final set position block in the system, the particles don't spawn at that position in the scene view. This was really confusing to me. There is no indication why it wouldn't work - on the contrary, the values showing up in the fields make me expect that it should be working. Or is it a bug?
     
  12. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Sure thing! :)

    Vector3 types are not spaceable (i.e. they do not contain information on whether the values are in world or local space), while Position types are, so if you are trying to convert a Vector3 to a Position, you you'll have to manually set what space you want these values to be (by toggling the L/W icon):


    Can you please provide some visuals? I'm not quite sure what this is referring to. It could be the space consideration we discussed before, but hard to tell.
     

    Attached Files:

    ashtorak likes this.
  13. ashtorak

    ashtorak

    Joined:
    Feb 19, 2014
    Posts:
    53
    This is my setup:

    vfx graph position 1.PNG

    I want to move the position of this torus in world space. Doing it like this does nothing when I change the y-value for example, even though it shows up on the right. However, and I just found now that it works like this for some reason:

    vfx graph position 2.PNG

    Now, when I change y, it moves the effect in the scene view accordingly.
    There must be some difference how the Vector3 as exposed property is funneled to the block compared to the other Vector3, which is really odd and unexpected. Especially since it shows the value on the torus block in both cases.
     
  14. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Are you per chance overwriting your exposed flameHitPoint in the inspector?

    Here is an example with color: New Color (green by default) is exposed and modified in the visual effect component to be red. Changing the default value in blackboard won't matter, as you are overwriting it later with what you have in the inspector (red). If you untick the overwrite checkbox in the inspector however, you can go back to modifying and reusing the default value:
     

    Attached Files:

    ashtorak likes this.
  15. ashtorak

    ashtorak

    Joined:
    Feb 19, 2014
    Posts:
    53
    Yes, that's it! Thank you very much! :)
    So you have to be really careful when editing the effect in the graph and looking for the result in the scene view when you have it attached on some object. In hindsight, it's a pretty obvious mistake. I guess, you have to get used to the concept a bit.
     
    VladVNeykov likes this.
  16. Liderangel

    Liderangel

    Joined:
    Jul 8, 2018
    Posts:
    101

    Sorry about the delay, we are dealing with some other shader issues, but this worked perfectly, thank you very much!
     
    VladVNeykov likes this.
  17. betaFlux

    betaFlux

    Joined:
    Jan 7, 2013
    Posts:
    112
    Hi, I created a VFX Graph for SkinnedMeshRenderer effects and need to assign character roots to the VFXPropertyBinder at runtime, since I spawn characters and pooled vfx graphs on the fly. Can someone explain how to do that?
     
  18. konzeptzwei

    konzeptzwei

    Joined:
    Feb 10, 2006
    Posts:
    64
    the link for the github repository is 404! Is there a new link somewhere?
     
  19. PaulDemeulenaere

    PaulDemeulenaere

    Unity Technologies

    Joined:
    Sep 29, 2016
    Posts:
    154
    Hello!
    The repro ScriptableRenderPipeline has been migrated to Graphics (see this message).
    About VFXTransformBinder.cs, you can now find the code reference here:
    https://github.com/Unity-Technologi...yBinding/Implementation/VFXTransformBinder.cs

    Hello,
    VFXTransformBinder is actually private but if you have copied this helper in your project, you can modify the Target property. Alternatively, you can reproduce the same behavior (see this earlier post)

    Two side remarks:
    - You can also directly expose a Matrix4x4 instead of transform in VisualEffect
    - Since 2022.2a14, the Skinned Mesh Sampling integrates (optionally) the root bone transform
     
    betaFlux likes this.
  20. VoltaDev

    VoltaDev

    Joined:
    Apr 13, 2021
    Posts:
    4

    Appears that this doesn't work for a Sphere property's sub properties. Have tried your suggestion and also upper case Scale. Any help is much appreciated.
     
  21. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hey @VoltaDev ,
    The naming for individual shape properties can be a bit tough to get right since there's no native shader type for any of them. If you have an exposed Sphere type named New Sphere, your properties will be:
    position: New Sphere_transform_position
    angles: New Sphere_transform_angles
    scale: New Sphere_transform_scale
    radius: New Sphere_radius

    For an Arc Sphere type called New Arc Sphere, they'll be:
    position: New Arc Sphere_sphere_transform_position
    angles: New Arc Sphere_sphere_transform_angles
    scale: New Arc Sphere_sphere_transform_scale
    radius: New Arc Sphere_sphere_radius
    arc: New Arc Sphere_arc

    So you don't guess for other shapes in the future (as the naming is not very discoverable), you can do the following:
    First, overwrite in the inspector the properties you'd like to see the shader name for:


    Then right click on the inspector window and change your inspector to Debug mode:


    Then you can scroll down and see for each type (i.e. Vector3 for the position property, float for the radius property, etc.) the list of the actual property names you can use to set directly with script:


    Hope this helps!
     

    Attached Files:

    Ryut, Julien-A, Qriva and 2 others like this.
  22. VoltaDev

    VoltaDev

    Joined:
    Apr 13, 2021
    Posts:
    4

    Thank you so much! This is super helpful.
     
    VladVNeykov likes this.
  23. Liderangel

    Liderangel

    Joined:
    Jul 8, 2018
    Posts:
    101
    @VladVNeykov hey, we are getting a bunch of "Value of name 'VARIABLE' was not found". I know this error can occur when the variable name is not the correct one or we are using the incorrect "SetX" (for instance using SetFloat instead of SetBool). That's not the case in our situation. We found that when you click on "Compile" all the errors are fixed and you can keep playing normally. Of course this in the editor, but on build there is no "compile" and thus all the errors keep popping up.

    How can we precompile all the VFX Graphs? Thanks!
     
  24. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hi @Liderangel ,

    I haven't encountered this, can you share a bit more info? What are you setting via script, and what is exposed in your blackboard?

    If a compile fixes it, do you also save the graph to preserve any changes? (I think sometimes in version control or upgrading / importing effects from different versions you may need to re-save your VFXs)
     
    Liderangel likes this.
  25. Liderangel

    Liderangel

    Joined:
    Jul 8, 2018
    Posts:
    101

    I think this solved it! We did updated Unity a couple of days ago so that could have been it. Weird that this is needed, it was quite time consuming.

    Thanks!
     
  26. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    If you encounter this again, there's a menu option under Edit > VFX > Rebuild And Save All VFX Graphs for next time :)
     

    Attached Files:

    Liderangel and Qriva like this.
  27. Liderangel

    Liderangel

    Joined:
    Jul 8, 2018
    Posts:
    101

    Good to know! That saves a lot of time. Is there an equivalent for "Open and Compile All"? Because what we found is that you need to manually compile the effects in other to see them locally, and sometimes in build you just don't see them because the PC that made the build hasn't compiled said effect. Maybe it's a setting in Build Settings that we are missing.
     
  28. akhileshrao

    akhileshrao

    Joined:
    Oct 11, 2020
    Posts:
    6
    How does this work if I want to expose bools and Vector3 materials? For me, Only my "float" options can be set in the VFX Property Bonder, but any varibbles of other types (Vector3 and bools) are seen as options
     

    Attached Files:

  29. HDProDesignTeam

    HDProDesignTeam

    Joined:
    Mar 16, 2019
    Posts:
    8
    Hi everyone.
    I searched lots of discussions but could not find a solution. I am creating vfx particle systems and setting some exposed properties from mono behavior. Everything works fine, but when you try to download this from CDN, or copy it to another project it gives an error which says could not find the exposed parameter(s). When you open the vfx and close it without making any change everything returns to normal again.

    Is there anyone who experienced this issue before or have solution on this.

    Thanks in advance.