Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

"Look At" block in UpdateParticle throws Error

Discussion in 'Visual Effect Graph' started by xXPancakeXx, Sep 22, 2021.

  1. xXPancakeXx

    xXPancakeXx

    Joined:
    Mar 14, 2015
    Posts:
    55
    Hello,

    im trying to get the angles of the looking direction using the "Look At" block, but this block doesnt seem to work on the GPU. This is what I connected when the following error shows up in the console. Do you guys know how to make it work or do I have to make my own "Look At"?
    Thanks in advance for any help.


    upload_2021-9-22_11-38-53.png


    Code (CSharp):
    1. vfx_projectilesCurved : Exception while compiling expression graph: System.InvalidOperationException: The expression UnityEditor.VFX.VFXExpressionExtractAnglesFromMatrix is not valid as it have the invalid flag: InvalidOnGPU, PerElement
    2.   at UnityEditor.VFX.VFXExpressionGraph.BuildMapper (UnityEditor.VFX.VFXContext context, System.Collections.Generic.Dictionary`2[TKey,TValue] dictionnary, UnityEditor.VFX.VFXDeviceTarget target)
    3.  
     
  2. VladVNeykov

    VladVNeykov

    Unity Technologies

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

    I don't think the matrix-to-euler operation to get the angles is available on the GPU. Depending on what you are trying to do, there are a few options:

    The simplest option is to just make particles face the velocity, and then use Add Angle if you needed to orient them slightly differently:


    This will give you something like this:


    You can also subtract the old and current position, normalize it, and then use that as a orientation vector. It might not be quite what you like because it's possible that position == oldPosition in which case you'll produce a zero vector.


    Other things you can explore is setting the axes manually or using the other orient blocks.
    If you have a scenario that won't work with these options, please share it :)
     

    Attached Files:

  3. xXPancakeXx

    xXPancakeXx

    Joined:
    Mar 14, 2015
    Posts:
    55
    Oh thanks for the different approaches, did not think at all about the orient block.
    Although I went for the custom route via my own angles calculation, this are very neat ways you presented.

    But it would be good if you guys could document where some functions can be used or at least provide a proper error message.
     
  4. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Yup, completely agree; we have an error feedback system that can pop a little notification next to the thing which doesn't work or works in an unexpected ways and are slowly populating this with scenario-specific warnings. Will make sure we add this scenario as well to it, thanks for bringing it up!
     
  5. techtonicplates

    techtonicplates

    Joined:
    Jan 1, 2018
    Posts:
    5
    Could I see a quick example of what LookAt angles would actually be used for? Thanks!

    I'm looking into something similar to what LookRotation would do without having to use Orient. I've gotten close with getting Rad2Deg and Set Angle but not close enough with the normalized target position.

    This is the formula I'm looking to convert
    Quaternion.LookRotation(Vector3.forward, dir.normalized) * Quaternion.Euler(0, 0, Mathf.Rad2Deg * p)


    upload_2022-5-7_23-22-18.png