Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by keyp3r · Nov 12, 2018 at 07:16 AM · shadershadersnullreferenceexceptionruntimeargumentexception

Null shader on camera at runtime?

I have a few custom post-effect esq shaders on my camera, all of which run great in editor but cause the following error to be thrown when built out and run. Each shader throws this same error in a similar location (material creation):

 ArgumentNullException: Argument cannot be null.
 Parameter name: shader
   at (wrapper managed-to-native) UnityEngine.Material:CreateWithShader (UnityEngine.Material,UnityEngine.Shader)
   at UnityEngine.Material..ctor (UnityEngine.Shader shader) [0x00000] in <filename unknown>:0 
   at DepthFog.Start () [0x0000c] in C:\Users\marsh\Dropbox\GameProjects\Cold\Cold\Assets\_Scripts\_Post\DepthFog.cs:20 
  
 (Filename: C:/Users/marsh/Dropbox/GameProjects/Cold/Cold/Assets/_Scripts/_Post/DepthFog.cs Line: 20)


The line it's complaining about in the script listed looks like this (the "mat = new Material(Shader..." bit):

 void Start () {
         mat = new Material(Shader.Find("Hidden/DepthFog"));
         cam = gameObject.GetComponent<Camera>();
     }
 
     void OnRenderImage(RenderTexture src, RenderTexture dest){
         if(mat != null){
             cam.depthTextureMode = DepthTextureMode.Depth;
             mat.SetColor("_Tint", FogTint);
             mat.SetFloat("_Brightness", DepthBrightness);
             mat.SetFloat("_DOffset", DepthOffset);
             mat.SetFloat("_Squash", DepthSquash);
 
             Graphics.Blit(src,dest,mat);
         }
     }
 }

This screen effect and script worked fine in Unity 2017 (I recently upgraded), and (again) works great in editor. Hell, it doesen't even throw build errors, just run-time errors..

I've seen elsewhere that it might be linked to bad OS workspace mappings (a Unity bug mapping 32-bit asset paths as if they were 64), but I'm on a 64-bit OS, and the solutions to those would seemingly break my OS. Anyone have anything here? I'm at a loss.. Here's the full output log And here's the script (no compiler errors):

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 [ExecuteInEditMode]
 public class DepthFog : MonoBehaviour {
 
     [Range(0,10)]
     public float DepthBrightness = 0f;
     [Range(0,10)]
     public float DepthSquash = 0f;
     public float DepthOffset = 0f;
     public Color FogTint = Color.white;
 
     private Material mat;
     private Camera cam;
 
     // Use this for initialization
     void Start () {
         mat = new Material(Shader.Find("Hidden/DepthFog"));
         cam = gameObject.GetComponent<Camera>();
     }
 
     void OnRenderImage(RenderTexture src, RenderTexture dest){
         if(mat != null){
             cam.depthTextureMode = DepthTextureMode.Depth;
             mat.SetColor("_Tint", FogTint);
             mat.SetFloat("_Brightness", DepthBrightness);
             mat.SetFloat("_DOffset", DepthOffset);
             mat.SetFloat("_Squash", DepthSquash);
 
             Graphics.Blit(src,dest,mat);
         }
     }
 }
 
 
 

Thanks for taking a look! I appreciate it a ton.

output-log.txt (1.8 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by AdamSt · Nov 09, 2020 at 04:31 PM

For me the problem was a "Flare layer" added on camera. We were upgrading project from LWRP to URP, there was some post process on scene. After deleting object with PP this problem appeared. After deleting "Flare layer" from camera, problem disappeared.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Davidjsap · Dec 19, 2018 at 05:16 PM

Did you find an answer to this problem @keyp3r ? Running in to the same thing :/

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image keyp3r · Dec 19, 2018 at 05:24 PM 0
Share

I have not, no.. Sorry you're hitting it, but also glad i'm not alone at least. If I find something I'll be sure to post it.

avatar image
0

Answer by vigadeveloper · Mar 01, 2019 at 04:03 AM

@Davidjsap I had a similar issue. I solved it by creating a shader variant collection and added the necessary shaders.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

165 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Set shader's AlphaCutoff programmatically in HDRP 1 Answer

Trees appearing as black square when oculus is plugged in 0 Answers

Replacing Shader At Runtime. 1 Answer

UI Blur shader not working 0 Answers

How to do an outline shader?,How to do an outline? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges