- Home /
 
RenderTexture being wiped/changed on play or undo.
I have a system where I'm using a custom shader to blit some information into a RenderTexture, which I then display using World Space canvases and RawImages. It works fine in terms of generating the images, but if I enter play mode, or if I say, move one of the canvases and use "undo", the RenderTexture is replaced with a blank one, and the RawImage has lost its reference.
I've checked my code and I'm never altering the RenderTexture here. The RenderTexture is set to be serialized and I even stuck in an "EditorUtility.SetDirty(this)" after its generated.
So in my main class I have this function:
 private void GenerateTexture()
 {
     m_renderTexture = m_textureCreator.GenerateTextureFromField(m_gravityPoints, m_resolution);
     m_rawImage.texture = m_renderTexture;
 
 #if UNITY_EDITOR
     EditorUtility.SetDirty(this);
 #endif
 }
 
               This method generates the texture:
 public RenderTexture GenerateTextureFromField(Vector2[] field, int fieldSize)
 {
     using (m_computeBuffer = new ComputeBuffer(field.Length, 8))
     {
         m_computeBuffer.SetData(field);
 
         m_material.SetBuffer(POINT_ARRAY_PROPERTY, m_computeBuffer);
         m_material.SetInt(POINT_COUNT_PROPERTY, field.Length);
         m_material.SetInt(FIELD_SIZE_PROPERTY, fieldSize);
 
         // commented this part out (which is meant to clear the current render texture)
         // to see if it was the reason. it wasn't.
 
         //RenderTexture rt = RenderTexture.active;
         //RenderTexture.active = m_renderTexture;
         //GL.Clear(true, true, Color.clear);
         //RenderTexture.active = rt;
 
         RenderTexture temp = RenderTexture.GetTemporary(m_renderTexture.width, m_renderTexture.height);
 
         Graphics.Blit(temp, m_renderTexture, m_material);
 
         RenderTexture.ReleaseTemporary(temp);
     }
 
     return m_renderTexture;
 }
 
               Any ideas what could be causing this? Thank you!
Your answer
 
             Follow this Question
Related Questions
Black Screen in Android when calling compute shader dispatch in Update 0 Answers
Render Texture in Render Texture not Rendering? 0 Answers
How to read self when CustomRenderTexture dimension is Tex2DArray 0 Answers
Compute Shader and mipmaps auto-generation 0 Answers
How to update texture during runtime to display damage? 0 Answers