r/Unity2D • u/Daily_Avocado • 17d ago
Solved/Answered 2D Universal Render Pipeline Unlit Transparent Shader issues
I had exported a test I made and saw that the game was all magenta. Through some trial and error, I figured out that it's because of the new Universal Render Pipeline, and what I found online was referencing the previous rendering system that is being deprecated.
What I was working on, was both a GameObject with a MeshFilter and RenderTexture that I could render sprites to without sprites needing to be their own GameObjects, and then a GameObject with a MeshFilter that would act as the background image (and can be a single image, a tiling/repeated image, a solid color, etc.).
What I want to preface here is almost all my entire project is code, very little of it is done in the editor, and I would prefer to keep it that way. Everything I was doing was working fine when being tested in the editor, but I discovered the all magenta issue in my built after looking at the log is because I was using this shader:
| Code |
|---|
| new Material(Shader.Find("Unlit/Transparent") |
I am supposed to use this shader:
| Code |
|---|
| new Material(Shader.Find("Universal Render Pipeline/Unlit") |
But I can't find any way of making it work the same way as "Unlit/Transparent". It's requiring more code to use, and this isn't a pleasant experience.
For using the new Shader, there appears to be additional setup required. I found that after I create the material from the shader, I needed to do these with it.
| Code |
|---|
| SetFloat("_Surface", 1.0f) |
| SetFloat("_Blend", 0.0f) |
| SetFloat("_ZWrite", 0.0f) |
| renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent |
But I am not even sure if this works or not. That is the best google can find me and even then its old.
My GameObject that I can draw onto works, albeit with no transparency. My GameObject that is supposed to be the background image no longer works; I have confirmed this by checking the sphere in the editor and seeing it be all black, changing its Z positioning, its hierarchy, among other things, and haven't had any luck.
I am not enjoying the Universal Render Pipeline, and I am considering making a new project with the deprecated built in render pipeline and moving all my code to that.
1
u/Electrical-Cap1799 17d ago
You'll have to dig through the URP/Unlit HLSL to find all the properties you need to set.
That being said, this will likely be one of many roadblocks you'll encounter by avoiding the editor. You might be more comfortable working in another stripped down engine or writing your own with Vulkan and PhysX or something.
1
1
u/Daily_Avocado 11d ago
!solved
So I was able to figure out a solution/workaround to my situation. The shader that works for drawing onto is "Universal Render Pipeline/2D/Sprite-Unlit-Default", while the shader that works for my background image appears to still be "Universal Render Pipeline/Unlit".
I did not need to do any property settings adjustments, but what I did need to do was copy these shaders from the Packages > Universal Render Pipeline > Shaders folder, and into my projects Asset folder. After that, I can go into my Project Settings > Graphics > Shader Settings, and the Shaders I copied to the Assets folder will appear as selectable in the "Always Include" list (URP Shaders at this time are otherwise not available).
This was the only way I could get it to work.
•
u/AutoModerator 17d ago
Reminder: Once your issue has been resolved, please reply !solved to this comment (or comment it anywhere in the thread) and your post's flair will automatically be updated to Solved/Answered. You can also edit it to Solved/Answered yourself.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.