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);
}
}
}