How do you access the Visual Effect component’s Renderer section to be able to set Priority via scripting, rather than just through the inspector?
Is accessing the Priority via script even possible? Putting the inspector in debug mode doesn’t show the variables for the renderer section exists in the component itself. Also using Visual Studio Intellisense for the Visual Effect component doesn’t show any public options to set it either.
Also, is the Priority in the Visual Effect component related to material render queue sorting, or is it related to Mesh Renderer sorting priority for transparent objects? This page in the docs isn’t clear which one, but I’m assuming transparent material render queue?:
https://docs.unity3d.com/Packages/com.unity.visualeffectgraph@10.2/manual/VisualEffectComponent.html
But if so, it’s not working correctly. I filed a bug on this the other day: 1305134
How does one set a Visual Effect material render queue to appear behind an HDRP transparent material that has its material transparent sort priority set to -5, for example?
@VladVNeykov some help pretty please?
Hi @Korindian ,
Apologies for the delay, @PaulDemeulenaere kindly looked into it and you can access the renderer priority via script like this:
var renderer = gameObject.GetComponent<Renderer>(); //VFXRenderer inherits from Renderer
if (renderer != null)
{
renderer.rendererPriority = 15;
}
VFX renderer priority, sorting, etc. are not very well explored at this stage, so if you run into any issues, please let us know or log a bug.
Thank you so much for responding. As mentioned in the second post, I did log a bug 2 weeks ago with a simple easy-to-reproduce project, but no one has taken a look at it yet: #1305134
QA got back to me, and said that sorting by material is not supported yet… however, after more testing, I found that it can be done, at least in version HDRP 10.2.2.
The rendererPriority in post #4 above is the same as the “Priority” property in the Visual Effect component’s inspector under the Renderer section. This property refers to the MeshRenderer’s priority as shown on this page in the docs under the section “Sorting By Priority”, NOT the material’s sorting priority.
The VFX Graph material’s sorting priority can currently only be set by scripting, using the method @VladVNeykov posted above to get the renderer. I can confirm that this also works with VFX Shader Graph shaders:
private int sortPriority = -10; // Or whatever HDRP sortPriority you want to set it to.
var renderer = vfxGameObject.GetComponent<Renderer>(); //VFXRenderer inherits from Renderer
if (renderer != null)
{
renderer.sharedMaterial.renderQueue = 3000 + sortPriority;
renderer.sharedMaterial.SetFloat("_TransparentSortPriority", sortPriority);
}
The sortPriority’s value is from -100 to 100 in HDRP according to this page in the docs under “Sorting by Material”.
Note that both the material renderQueue and float property “_TransparentSortPriority” must be set as one can get reset while refreshing the material’s inspector if the other is not set also, for example when switching the inspector debug mode, or expanding/collapsing the material inspector. At least this is the case with regular HDRP materials, not sure about VFX Graph shaders, but it’s there for completeness.
It would be great if either this could be added to the docs, or if this functionality could be added to the Visual Effect component’s inspector, since sorting with HDRP shaders already works.
Hi @Korindian ,
Apologies, missed the part where you mentioned the bug, but glad you received a reply. So yes, in a nutshell, sorting still needs more attention on the VFX side as it needs to be address in a way which works for both HDRP and URP.
Some examples:
- sorting by render queue, i.e. Opaque/Transparent (supported in VFX/HDRP/URP)
- sorting by render queue offset, i.e. Transparent + n (supported in HDRP/URP, not yet exposed/officially supported by VFX. You’ve added your own queue offset, and can even implement it in your outputs like mentioned on ** this ** forum post, but we still need to look into the level it should be exposed (per output and/or per system), ensure it’s robust for all scenarios (e.g. what if the render queue contradicts the vfx output sorting order), etc.
- sorting by renderer priority (works in HDRP, don’t think URP has it).
TL;DR: it’s planned
Bump for sorting by mesh renderer priority similar to HDRP for URP
Please feel free to submit it as an idea request with some info on your use case so we prioritize this better compared to other requests.
Am I reading this correctly (not up with all the terminology yet) and is this what you are referring to @MCLiving88 ?
I want to render a VFX Graph in front of an object with transparency in URP (URP/Lit with Metallic+Transparent). See the images below.
With the earth spherical object set to Opaque I get the correct rendering as seen (blue VFX surrounding earth globe).
If I set the earth object to Transparent, so that I can fade it in and out selectively, I only get VFX that is not hidden by the earth object. Post #4 makes no difference. Haven’t tried Post #6.
Thanks!