Search Unity

Standard Assets SSAO Script problem

Discussion in 'Scripting' started by MonkeyKasai, Oct 1, 2015.

  1. MonkeyKasai

    MonkeyKasai

    Joined:
    Jan 4, 2014
    Posts:
    40
    Hey guys, Im trying to attach the SSAO script to my camera, if I drag it onto the camera it works fine. But when I try to make a script attach it to the camera I get the error
    "Object reference not set to an instance of an object UnityStandardAssets.ImageEffects.ScreenSpaceAmbientOcclusion.CreateMaterials () (at Assets/Plugins/ImageEffects/Scripts/ScreenSpaceAmbientOcclusion)"

    Code (CSharp):
    1.         private void CreateMaterials ()
    2.         {
    3.             if (!m_SSAOMaterial && m_SSAOShader.isSupported)
    4.             {
    5.                 m_SSAOMaterial = CreateMaterial (m_SSAOShader);
    6.                 m_SSAOMaterial.SetTexture ("_RandomTexture", m_RandomTexture);
    7.             }
    8.         }
    the "if(!m_SSAOMaterial && M_SSAOShader.isSupported)" is the line that the error goes to when i double click on it in the console

    When looking at the script after its been attached to the camera through my script the "SSAO Shader" and "Random Texture" are empty. and the script is turned off. I tried attaching the shader and texture to it manually but still couldn't turn it on.

    I also tried making a camera prefab and then instantiate with the SSAO script on and it still didn't work

    Hopefully someone can help me out

    Thanks in advance :)
     
  2. Rikland

    Rikland

    Joined:
    Mar 7, 2014
    Posts:
    5
    I had this problem recently and solved it by
    • creating public fields for the SSAO Shader and the Random Texture in the script that adds the SSAO shader
    • setting the those fields to the corresponding files in the editor
    • assigning them to the corresponding fields of the created ssao component in the Awake method of the script that adds the ssao component
    Perhaps there are more fields that needs to be initialized in your case. Personally I matched all of them.