Search Unity

Rendering camera but calling code does not set it up as current camera ERROR!

Discussion in 'Scripting' started by markashburner, Apr 2, 2020.

  1. markashburner

    markashburner

    Joined:
    Aug 14, 2015
    Posts:
    212
    Can someone please help me. I have been racking over this error for ages now and I can't seem to work it out. I am trying to RenderToCubemap. I have a couple of cameras setup in my scene and I have this script attached to a third camera. It renders to cube map but always throws me this error.

    I highly doubt I will get much response though which sucks. Unity's support has swayed quite a bit recently.


    Anyways here is my code:
    I would really appreciate it if someone could help. Thanks.

    Code (CSharp):
    1. public void CreateCubemap()
    2.     {
    3.         // create temporary camera for rendering
    4.      //   yield return new WaitForEndOfFrame();
    5.         cubemap = new Cubemap(1024, TextureFormat.RGBA32, false);
    6.         //  GameObject go = new GameObject("CubemapCamera");
    7.  
    8.  
    9.  
    10.         //   go.GetComponent<Camera>().cullingMask &= ~(1 << LayerMask.NameToLayer("BakeLayer"));
    11.  
    12.         // place it on the object
    13.         //  go.transform.position = renderFromPosition.position;
    14.         //   go.transform.rotation = Quaternion.identity;
    15.         // render into cubemap
    16.         GetComponent<Camera>().RenderToCubemap(cubemap);
    17.         positive_X = new Texture2D(1024, 1024);
    18.         positive_X.SetPixels(cubemap.GetPixels(CubemapFace.PositiveX));
    19.         positive_X.Apply();
    20.  
    21.         positive_Y = new Texture2D(1024, 1024);
    22.         positive_Y.SetPixels(cubemap.GetPixels(CubemapFace.PositiveY));
    23.         positive_Y.Apply();
    24.  
    25.         positive_Z = new Texture2D(1024, 1024);
    26.         positive_Z.SetPixels(cubemap.GetPixels(CubemapFace.PositiveZ));
    27.         positive_Z.Apply();
    28.  
    29.         negative_X = new Texture2D(1024, 1024);
    30.         negative_X.SetPixels(cubemap.GetPixels(CubemapFace.NegativeX));
    31.         negative_X.Apply();
    32.  
    33.         negative_Y = new Texture2D(1024, 1024);
    34.         negative_Y.SetPixels(cubemap.GetPixels(CubemapFace.NegativeY));
    35.         negative_Y.Apply();
    36.  
    37.         negative_Z = new Texture2D(1024, 1024);
    38.         negative_Z.SetPixels(cubemap.GetPixels(CubemapFace.NegativeZ));
    39.         negative_Z.Apply();
    40.  
    41.    
    42.     }