MirrorReflection script, adding image effects
Hi! I'm using the MirrorReflection4 script from the wiki in my game. ( http://wiki.unity3d.com/index.php/MirrorReflection4 )
It works great by default. I'm using the Edge Detection image effect on my game and wanted to add it to the reflection so it properly matches what you see in the world.
The way I did it was by adding this:
using UnityStandardAssets.ImageEffects;
and then on the script where I found this line:
reflectionCamera.gameObject.AddComponent<FlareLayer>();
I added this right below it:
reflectionCamera.gameObject.AddComponent<EdgeDetection>();
Now here is the part I'm stuck on: this works great in editor, but in builds I get an error and the edge detection doesn't happen:
NullReferenceException: Object reference not set to an instance of an object
This is the full error on the log:
Missing shader in Mirror Refl Camera id24260 for 16178 (UnityStandardAssets.ImageEffects.EdgeDetection)
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
UnityStandardAssets.ImageEffects.PostEffectsBase:CheckShaderAndCreateMaterial(Shader, Material) (at D:\Unity\GAME\Assets\Standard Assets\Effects\ImageEffects\Scripts\PostEffectsBase.cs:21)
UnityStandardAssets.ImageEffects.EdgeDetection:CheckResources() (at D:\Unity\GAME\Assets\Standard Assets\Effects\ImageEffects\Scripts\EdgeDetection.cs:39)
UnityStandardAssets.ImageEffects.EdgeDetection:OnRenderImage(RenderTexture, RenderTexture) (at D:\Unity\GAME\Assets\Standard Assets\Effects\ImageEffects\Scripts\EdgeDetection.cs:72)
UnityEngine.Camera:Render()
MirrorReflection:OnWillRenderObject() (at D:\Unity\GAME\Assets\_ASSETS\mirror\MirrorReflection.cs:86)
(Filename: D:/Unity/GAME/Assets/Standard Assets/Effects/ImageEffects/Scripts/PostEffectsBase.cs Line: 21)
NullReferenceException: Object reference not set to an instance of an object
at UnityStandardAssets.ImageEffects.EdgeDetection.OnRenderImage (UnityEngine.RenderTexture source, UnityEngine.RenderTexture destination) [0x00056] in D:\Unity\GAME\Assets\Standard Assets\Effects\ImageEffects\Scripts\EdgeDetection.cs:79
UnityEngine.Camera:Render()
MirrorReflection:OnWillRenderObject() (at D:\Unity\GAME\Assets\_ASSETS\mirror\MirrorReflection.cs:86)
(Filename: D:/Unity/GAME/Assets/Standard Assets/Effects/ImageEffects/Scripts/EdgeDetection.cs Line: 79)
Any ideas how to fix it, and why it works in editor but not in build? Thanks in advance!
Answer by terrivellmann · Mar 23, 2017 at 03:07 PM
So I figured it out, thanks to help I got on twitter, this is what fixed it: instead of just
reflectionCamera.gameObject.AddComponent<EdgeDetection>();
I added
reflectionCamera.gameObject.AddComponent<EdgeDetection>();
EdgeDetection edgedetection = reflectionCamera.gameObject.GetComponent(typeof(EdgeDetection) ) as EdgeDetection;
edgedetection.edgeDetectShader = Shader.Find("Hidden/EdgeDetect");
So I guess the effect was being added without a shader attached.
Your answer
Follow this Question
Related Questions
Image Effects keep on rendering 0 Answers
system time image effects 0 Answers
Shiny surface shows wrong side reflection of non static character 0 Answers
CRT Shader how optimize?! 1 Answer
Fairly new to programming; Need ideas on how to do this script 1 Answer