Help Object reference not set to an instance of an Object

Hello , im very new with unity and #C
i try to add new Object in script
for example in script have only 2 object SnowMan and SnowTree i try to add more object by copy past
but when i want Chang or add new name for example monster ,it give me this massage

The exact error message is here: NullReferenceException: Object reference not set to an instance of an object

THIS THE FULL Script

using UnityEngine;
using System.Collections;
using Vuforia;
public class MainController : MonoBehaviour
{
//[SerializeField]
//protected RenderTextureCamera _SnowManRTC;
//[SerializeField]
//protected RenderTextureCamera _SnowTreeRTC;
private IEnumerator _SendTexture(GameObject go, RenderTexture rt)
{
go.SetActive(false);
//yield return new WaitForSeconds(0.F);
yield return new WaitForEndOfFrame();
//var rt = RenderTextureCamera.CameraOutputTexture;
var FrameTexture = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false);
RenderTexture.active = rt;
FrameTexture.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
RenderTexture.active = null;
FrameTexture.Apply();
go.GetComponent().ApplyTexture(FrameTexture);
go.SetActive(true);
}
void OnGUI()
{
//return;
//if (_snowManGo != null && GUILayout.Button(“Apply Color to SnowMan”))
//{
// StartCoroutine(_SendTexture(_snowManGo));
//}
//if (_snowManGo != null && GUILayout.Button(“Apply Color to SnowTree”))
//{
// StartCoroutine(_SendTexture(_snowTreeGo));
//}
}
private GameObject _snowManGo;
private GameObject _snowTreeGo;
public void OnTrackingFound(GameObject go)
{
print("OnTrackingFound " + go);
switch (go.name)
{
case “snowman”:
_snowManGo = go;
if (RenderTextureCamera.CameraOutputTexture != null)
StartCoroutine(_SendTexture(_snowManGo, RenderTextureCamera.CameraOutputTexture));
break;
case “snowtree”:
_snowTreeGo = go;
if (RenderTextureCamera.CameraOutputTexture != null)
StartCoroutine(_SendTexture(_snowTreeGo, RenderTextureCamera.CameraOutputTexture));
break;
}
}
public void OnTrackingLost(GameObject go)
{
print("OnTrackingLost " + go);
switch (go.name)
{
case “snowman”:
_snowManGo = null;
break;
case “snowtree”:
_snowTreeGo = null;
break;
}
}
}

@uosland

hi there, you’ll get an answer more likely if:

Also, paste the full error message. It includes line numbers - we’re not going to look through the entire script to find the error.
(and your code will have line numbers on it if you used code tags)

@eses @StarManta

This the Full code without Chang from me

using UnityEngine;
using System.Collections;
using Vuforia;

public class MainController : MonoBehaviour
{
    //[SerializeField]
    //protected RenderTextureCamera _SnowManRTC;
    //[SerializeField]
    //protected RenderTextureCamera _SnowTreeRTC;

    private IEnumerator _SendTexture(GameObject go, RenderTexture rt)
    {
        go.SetActive(false);
        //yield return new WaitForSeconds(0.F);

        yield return new WaitForEndOfFrame();

        //var rt = RenderTextureCamera.CameraOutputTexture;
        var FrameTexture = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false);
        RenderTexture.active = rt;
        FrameTexture.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
        RenderTexture.active = null;

        FrameTexture.Apply();

        go.GetComponent<ColorObject>().ApplyTexture(FrameTexture);
        go.SetActive(true);       
    }

    void OnGUI()
    {
        //return;
        //if (_snowManGo != null && GUILayout.Button("Apply Color to SnowMan"))
        //{
        //    StartCoroutine(_SendTexture(_snowManGo));
        //}

        //if (_snowManGo != null && GUILayout.Button("Apply Color to SnowTree"))
        //{
        //    StartCoroutine(_SendTexture(_snowTreeGo));
        //}
    }

    private GameObject _snowManGo;
    private GameObject _snowTreeGo;

    public void OnTrackingFound(GameObject go)
    {
        print("OnTrackingFound " + go);

        switch (go.name)
        {
            case "snowman":
                _snowManGo = go;
                if (RenderTextureCamera.CameraOutputTexture != null)
                    StartCoroutine(_SendTexture(_snowManGo, RenderTextureCamera.CameraOutputTexture));
                break;
            case "snowtree":
                _snowTreeGo = go;
                if (RenderTextureCamera.CameraOutputTexture != null)
                    StartCoroutine(_SendTexture(_snowTreeGo, RenderTextureCamera.CameraOutputTexture));
                break;
        }
    }

    public void OnTrackingLost(GameObject go)
    {
        print("OnTrackingLost " + go);
        switch (go.name)
        {
            case "snowman":
                _snowManGo = null;
                break;
            case "snowtree":
                _snowTreeGo = null;
                break;
        }
    }
}

and this code aftre i had add new imagetarget monster

Assets/_Scripts/MainController.cs(85,13): error CS0163: Control cannot fall through from one case label `case “snowman”:’ to another

using UnityEngine;
using System.Collections;
using Vuforia;

public class MainController : MonoBehaviour
{
    //[SerializeField]
    //protected RenderTextureCamera _SnowManRTC;
    //[SerializeField]
    //protected RenderTextureCamera _monsterRTC;
    //[SerializeField]
    //protected RenderTextureCamera _SnowTreeRTC;

    private IEnumerator _SendTexture(GameObject go, RenderTexture rt)
    {
        go.SetActive(false);
        //yield return new WaitForSeconds(0.F);

        yield return new WaitForEndOfFrame();

        //var rt = RenderTextureCamera.CameraOutputTexture;
        var FrameTexture = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false);
        RenderTexture.active = rt;
        FrameTexture.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
        RenderTexture.active = null;

        FrameTexture.Apply();

        go.GetComponent<ColorObject>().ApplyTexture(FrameTexture);
        go.SetActive(true);       
    }

    void OnGUI()
    {
        //return;
        //if (_snowManGo != null && GUILayout.Button("Apply Color to SnowMan"))
        //{
        //    StartCoroutine(_SendTexture(_snowManGo));
        //}
        //return;
        //if (_monsterGo != null && GUILayout.Button("Apply Color to monster"))
        //{
        //    StartCoroutine(_SendTexture(_monsterGo));
        //}

        //if (_snowManGo != null && GUILayout.Button("Apply Color to SnowTree"))
        //{
        //    StartCoroutine(_SendTexture(_snowTreeGo));
        //}
    }

    private GameObject _snowManGo;
    private GameObject _monsterGo;
    private GameObject _snowTreeGo;

    public void OnTrackingFound(GameObject go)
    {
        print("OnTrackingFound " + go);

        switch (go.name)
        {
            case "snowman":
                _snowManGo = go;
                if (RenderTextureCamera.CameraOutputTexture != null)
                    StartCoroutine(_SendTexture(_snowManGo, RenderTextureCamera.CameraOutputTexture));
                break;
            case "monster":
                _monsterGo = go;
                if (RenderTextureCamera.CameraOutputTexture != null)
                    StartCoroutine(_SendTexture(_snowManGo, RenderTextureCamera.CameraOutputTexture));
                break;
            case "snowtree":
                _snowTreeGo = go;
                if (RenderTextureCamera.CameraOutputTexture != null)
                    StartCoroutine(_SendTexture(_snowTreeGo, RenderTextureCamera.CameraOutputTexture));
                break;
        }
    }

    public void OnTrackingLost(GameObject go)
    {
        print("OnTrackingLost " + go);
        switch (go.name)
        {
            case "snowman":
                _snowManGo = null;
            case "monster":
                _monsterGo = null;
                break;
            case "snowtree":
                _snowTreeGo = null;
                break;
        }
    }
}

That error looks like you need a “break;” after that snowman line in the switch statement.