Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Using camera.targetTexture stalls application

Discussion in 'Scripting' started by GMM, Jul 16, 2015.

  1. GMM

    GMM

    Joined:
    Sep 24, 2012
    Posts:
    301
    In Unity 4.x.x releases i have been able to do the following to create a render texture and set the texture as a camera target, but it seems like no matter what i try and what Unity 5 engine revision i try to use, the application stalls whenever i try to set a rendertexture to a camera using "Camera.targetTexture".

    I am currently running engine version 5.1.1p4, but i have not been able to get it work on older version of Unity 5 either. The code works in the editor, but any deployed application will just stall, similar results on Windows, iOS and Android.

    The output log outputs the following:
    I would very much like to know what i am doing wrong, as i need to use Render Textures with Camera.targetTexture.

    The problem can be replicated with this simple class:

    Code (CameraTester.cs):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [RequireComponent(typeof(Camera))]
    5. public class CameraTester : MonoBehaviour
    6. {
    7.     public RenderTexture renderTex;
    8.     public Camera camera;
    9.  
    10.     void Awake ()
    11.     {
    12.         // Get the camera component
    13.         camera = gameObject.GetComponent<Camera>();
    14.  
    15.         // Set up the render texture
    16.         renderTex = new RenderTexture(256, 256, 24, RenderTextureFormat.ARGB32);
    17.         renderTex.filterMode = FilterMode.Bilinear;
    18.  
    19.         // Create the render texture
    20.         renderTex.Create();
    21.  
    22.         // Set the render texture to the camera
    23.         camera.targetTexture = renderTex;
    24.     }
    25.  
    26.     void OnGUI()
    27.     {
    28.         // Determine if we have a texture
    29.         if (renderTex)
    30.         {
    31.             // Draw the texture to the screen
    32.             GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), renderTex);
    33.         }
    34.     }
    35. }
    36.  
     
  2. GMM

    GMM

    Joined:
    Sep 24, 2012
    Posts:
    301
    Has there been any updates on this issue? I opened a bug report that was filed as a known issue, but as of 5.2.0f3 the problem has still not been fixed, is nobody using camera.targetTexture at all?
     
  3. GMM

    GMM

    Joined:
    Sep 24, 2012
    Posts:
    301
    Nobody using camera.targetTexture?
     
  4. GMM

    GMM

    Joined:
    Sep 24, 2012
    Posts:
    301
    The above code does not work, i have however managed to create a solution that does what i want, so consider this one solved until Unity breaks the other method.
     
  5. sauerkraut

    sauerkraut

    Joined:
    Feb 21, 2014
    Posts:
    23
    I have the same problem. Would you mind posting what your workaround was? Pulling my hair out. Don't want to have to go back to 4.x.x....
     
  6. Devin-Q

    Devin-Q

    Joined:
    Sep 1, 2015
    Posts:
    1
    Did you add the RenderTexture to Main Camera and there was the only one camera? Try adding a new camera....And as far as i know, there must be two cameras in the scene.
     
    Last edited: Dec 26, 2015
  7. vvander

    vvander

    Joined:
    Jan 18, 2011
    Posts:
    72
    Any updates on this? We are seeing this error even though everything works as expected.
     
  8. Roshan123456

    Roshan123456

    Joined:
    Jul 31, 2018
    Posts:
    1
    I still don't know how to solve this. Please people if you have solved this then comment your code or atleast inform us how to solve ours instead of telling that you have solved it