Search Unity

VFX Graph Sorting Layer with sprites

Discussion in 'Visual Effect Graph' started by Angelo13C, Feb 16, 2020.

  1. Angelo13C

    Angelo13C

    Joined:
    Feb 16, 2020
    Posts:
    11
    I am making a 2D game with URP.
    After some problems, I've found out that the particles are rendered on the Default Sorting layer.

    Now the problem is that I can't modify where the particles will be rendered based on the sprites Sorting Layer (the problem is not between 2 particle graphs, but between a particle graph and the sprites).

    I want some particles to be rendered on the foreground (in front of the player), others on the background of the sprites
     
    mciv and prak like this.
  2. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
  3. prak

    prak

    Joined:
    Apr 6, 2013
    Posts:
    3
    I really hope this get addressed.
     
  4. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    I'm facing the same issue. No way to manage sorting and order in layer with Sprites and in Images in UI. I really hope it will be fixed very soon !

    Thanks
     
  5. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    Sorry to bump,

    Just want to be sure - So if I use URP + VFX + Sprites or Images (meaning sorting layers and order in layers) there is no way to manage what should be in front or behind ? I tried to change emission world position, visual effect transparency priority etc. but without any success.

    Is it doable or definitely URP + VFX + 2D is dead ?
     
  6. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hi @bali33 , not dead, just not born yet :) The URP integration for VFX is still being worked on and there are a number of features (this, lit particles, camera buffer access) which are not integrated yet.

    This user has mentioned implementing it for themselves; I haven't tried it, but maybe it will work for you?
    https://forum.unity.com/threads/added-render-queue-to-vfx-graph-unity-2019-2.820749/
     
  7. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    Hello,

    Glad to hear that ! Is that something we can expect in the first 2020 release ?

    I did not try to the solution you mentioned because not sure how it is related to my issue. How to relate sorting layer to "Transparent + N" value ?

    Thanks.
     
  8. VladVNeykov

    VladVNeykov

    Unity Technologies

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

    I can't say for certain when it will be available, it's a good policy to not have a production dependency on unreleased features landing in.

    I implemented the sorting from the link locally in v. 7.3.1 and it seems to work fine if you are trying to sort VFX with other transparent objects:


    This is not officially supported yet, so please use the attached file (replace the one in the VFX packages folder) at your own discretion. It may also not upgrade well, though the change is two lines of code (the ones containing customRenderQueue) so it should be easy to manually add in future versions. You'll probably need to also copy over the VFX package folder into your project's Packages folder so the changes will persist when you close Unity.

    Please bear with us until this is officially supported, but hope this helps should you want to try it out beforehand!
     

    Attached Files:

    florianhanke and bali33 like this.
  9. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    Thanks a lot ! I'll check that tomorrow morning !
     
    VladVNeykov likes this.
  10. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    Hello,

    I tried to copy-paste the file, so erased the orginal one, at /Library/PackageCache/com.unity.visualeffectgraph@7.3.1/Editor/Models/Contexts/Implementations but as soons as I restart Unity the file is restored as its original version. I also tried to modified manually the file but sam things happened.

    Am'I missing something ? Thanks.
     
  11. VladVNeykov

    VladVNeykov

    Unity Technologies

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

    Should be this part:
     
  12. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    Hum, next time I'll read twice !

    I'm going to do that, thanks.
     
  13. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    So, I moved the package, the modification stays, that's good. But I'm unable to have VFX in front of UI images (UI layer) whatever render queue value I set. I'm really disappointed here.
     
  14. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hey @bali33 ,
    You'd encounter the same with regular sprites if your Canvas is in overlay mode (by default).
    Change it to screen space - camera and assign your main camera and it should work:
     

    Attached Files:

    florianhanke and valarnur like this.
  15. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    Hello,

    Actually I do use Canvas with Screen space - Camera and it does not work. I tried to put everything in the default layer and the default sorting layer. I set the custom render queue to 400 to all my VFX and all I can see is the bounds of the particles in the scene view.

    Is there anything else I should do ?

    Thanks
     
  16. VladVNeykov

    VladVNeykov

    Unity Technologies

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

    I believe sort order works only within items in the same sorting layer, in this case Default.
    Depending on your use case, you can keep your elements which need to be sorted with the VFX graph in the Default layer and sorting should work.

    Otherwise, if your project requires that you use different sorting layers I'm afraid your best bet is to wait until the work on full URP integration for the VFX Graph is complete.

    Hope this helps!
     
  17. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    Hello,

    I'm confused here because I have some VFX running on top of Sprites which means SprireRenderer which mean Layer, Sorting Layer and order in layer -> same as Image so what it does not work with them ?

    anyway, thanks for you help and you time. But to be honest I'm disappointed that a whole concept (2D, Sorting layers etc.) has been put asides like that and not ETA when it will be handled.
     
  18. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Are the SpriteRenderers on the Default sorting layer? If so, then the VFX's custom render queue should work with them.
    Same with UI sprites in the Screen Space - Camera canvas, as long as the Canvas and its UI is also on the default sorting layer. The gif I posted here seems to work fine when all sorting layers which need to sort with the VFX graph are set to Default.

    I can only ask for a bit of patience and understanding as everyone has been affected by the pandemic and providing an ETA right now is just not feasible. I'll reiterate that this is a feature still in development and if you have an imminent need for mixing particles with UI in URP, I would strongly recommend using the built-in Particle system.
     
  19. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    Hello,

    I tried to put everything on Default layer, Default Sorting Layer and put VFX with an absolutely huge customRenderQueue value, like 4000 ,and the VFX stays behind SpriteRenderers and Images. So not sure how to make this works.
     
  20. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    @bali33 can you share a small repro proejct?
     
  21. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    Hello,

    I'll try to do that ! This is client project so I do have to make the smallest repro projet as possible and avoid my client assets.

    Thanks
     
  22. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    Hello @VladVNeykov,

    I just dm you a repro scene, I hope it works and helps understand what's going on.

    Thank you very much.
     
  23. chad18e

    chad18e

    Joined:
    Nov 30, 2019
    Posts:
    3
    Hi @VladVNeykov ,

    Where can I find the VFX Package folder that should be copied to my project's Packages folder? Is it supposed to be located in my Unity installation folder?

    Thanks!
     
  24. VladVNeykov

    VladVNeykov

    Unity Technologies

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

    It should be within your project's /Library/PackageCache/ folder and appear as com.unity.visualeffectgraph@VersionNumber
     
  25. chad18e

    chad18e

    Joined:
    Nov 30, 2019
    Posts:
    3
    Great, thanks for your help!
     
    VladVNeykov likes this.
  26. Agentmass

    Agentmass

    Joined:
    Jun 19, 2020
    Posts:
    3
    Hi There!

    I wanted to check in regarding this issue as I haven't found a good workaround. I can place certain sprite sorting layers either in front or behind the Default layer which the VFX particles render on but there's no way for me to render certain VFX particles in front of sprites and certain VFX particles behind sprites.

    I tried using the file @VladVNeykov provided and received the following error:

    Code (CSharp):
    1. Library\PackageCache\com.unity.visualeffectgraph@10.2.2\Editor\Models\Contexts\Implementations\VFXMeshOutput.cs(25,50): error CS0115: 'VFXMeshOutput.outputUpdateFeatures': no suitable method found to override
    I diffed the file with my working directory and tried to keep only the changes that looked like made sense to me and I was able to get the render order dialog to appear however I was still not able to control the particle system rendering either behind or in front of specific sprite order layers.

    VFX graph is absolutely incredible and I was even able to render 70k particles on my 200 dollar Android phone at max speed without issues... this is honestly the only problem preventing me from using this feature in my game.

    Does anyone happen to have an alternative solution or an estimate of when sorting layers will be implemented?

    Thank you very much!
     
  27. Agentmass

    Agentmass

    Joined:
    Jun 19, 2020
    Posts:
    3
    Got it!

    I found the following post:
    https://forum.unity.com/threads/hdrp-visual-effect-renderer-priority-via-c-scripting.1035745/

    Which seems to talk about a similar issue however the solution offered in post #6 did not satisfy my layer problem with sprites.

    I wondered if the VFX renderer itself had the same sorting layer name / order properties as the sprite renderer and it does! The following code will allow you to set the render order / layer of a VFX particle system so they play nicely with sprite shapes:


    Code (CSharp):
    1. var renderer = gameObject.transform.Find("VFX").GetComponent<Renderer>();
    2.  
    3. renderer.sortingLayerName = "SomeRenderLayer";
    4. renderer.sortingOrder = 10;
    Leaving this here for anyone else that happens to google this issue and come across this post :)
     
  28. triangle4studios

    triangle4studios

    Joined:
    Jun 28, 2020
    Posts:
    33
    Blows my mind that unity didn't create this already:
    1.) Create a script named SortOrder.
    2.) Replace the code with this.
    3.) Drag and drop it onto any VFX Object.
    4.) Instantly have full control over sorting order in the editor, and game.

    No incompatibility issues can occur, because its merely adjusting the sort order.
    This should have been unity's first answer.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class SortOrder : MonoBehaviour
    4. {
    5.     public int sortingOrder = 570;
    6.     public Renderer vfxRenderer;
    7.     void OnValidate()
    8.     {
    9.             vfxRenderer = GetComponent<Renderer>();
    10.             if (vfxRenderer)
    11.                 vfxRenderer.sortingOrder = sortingOrder;
    12.     }
    13. }
     
    Ofenkatze and luislodosm like this.
  29. Fressbrett

    Fressbrett

    Joined:
    Apr 11, 2018
    Posts:
    97
    Small performance correction: If you have this on every VFX Object in your scene, pls cache the renderer like so, since GetComponent is notoriously slow and should be avoided whenever possible:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class SortOrder : MonoBehaviour
    4. {
    5.     public int SortingOrder = 570;
    6.     public Renderer VfxRenderer = null;
    7.  
    8.     private void Awake()
    9.     {
    10.         VfxRenderer = GetComponent<Renderer>();
    11.     }
    12.  
    13.     private void OnValidate()
    14.     {
    15.         if (VfxRenderer)
    16.             VfxRenderer.sortingOrder = SortingOrder;
    17.     }
    18. }
     
    Ofenkatze likes this.
  30. Red-Sprites

    Red-Sprites

    Joined:
    Jun 24, 2018
    Posts:
    8
  31. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hi, in which tutorial?
     
  32. MORFIUS_INC

    MORFIUS_INC

    Joined:
    Sep 26, 2018
    Posts:
    1
    Sorry for been late, but i guess i have answer for you.

    Code (CSharp):
    1. GameObject effectGO;
    2. var tmp = effectGO.AddComponent<VisualEffect>();
    3. tmp.visualEffectAsset = effect.effectAsset;
    4. tmp.GetComponent<Renderer>().sortingLayerName = "Foreground";
    Last line changes sorting layer, then first 3 creates game object with visual grath and binds VFX asset to it.