Using camera.targetTexture stalls application

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:

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(Camera))]
public class CameraTester : MonoBehaviour
{
    public RenderTexture renderTex;
    public Camera camera;

    void Awake ()
    {
        // Get the camera component
        camera = gameObject.GetComponent<Camera>();

        // Set up the render texture
        renderTex = new RenderTexture(256, 256, 24, RenderTextureFormat.ARGB32);
        renderTex.filterMode = FilterMode.Bilinear;

        // Create the render texture
        renderTex.Create();

        // Set the render texture to the camera
        camera.targetTexture = renderTex;
    }

    void OnGUI()
    {
        // Determine if we have a texture
        if (renderTex)
        {
            // Draw the texture to the screen
            GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), renderTex);
        }
    }
}

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?

Nobody using camera.targetTexture?

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.

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…

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.

Any updates on this? We are seeing this error even though everything works as expected.

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