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
  4. Dismiss Notice

error CS0029: Cannot implicitly convert type 'string' to 'UnityEngine.RenderTextureFormat'

Discussion in 'Scripting' started by Jekirutu, Apr 15, 2022.

  1. Jekirutu

    Jekirutu

    Joined:
    Jun 10, 2019
    Posts:
    14
    I am working on portals for my game and to make them seamless, I am using render textures to display the environment the player is supposed to teleport to.

    The only thing that wasn't getting "carried over" to the render texture is post-processing; and to get it to work I found colour format needed, but I don't know which variable format is required to apply it to the render texture through script.

    "Assets\Scripts\Player system\PortalViewAdjustment.cs(21,40): error CS0029: Cannot implicitly convert type 'string' to 'UnityEngine.RenderTextureFormat'​

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PortalViewAdjustment : MonoBehaviour
    6. {
    7.     public Camera cameraB;
    8.     public Material cameraMatB;
    9.     public Camera cameraA;
    10.     public Material cameraMatA;
    11.  
    12.  
    13.     // Start is called before the first frame update
    14.     void Start()
    15.     {
    16.         if (cameraB.targetTexture != null)
    17.         {
    18.             cameraB.targetTexture.Release();
    19.         }
    20.         cameraB.targetTexture = new RenderTexture(Screen.width , Screen.height , 24);
    21.         cameraB.targetTexture.format = "R32G32B32A32_SFLOAT";
    22.         cameraMatB.mainTexture = cameraB.targetTexture;
    23.  
    24.         if (cameraA.targetTexture != null)
    25.         {
    26.             cameraA.targetTexture.Release();
    27.         }
    28.         cameraA.targetTexture = new RenderTexture(Screen.width, Screen.height, 24);
    29.         cameraA.targetTexture.format = "R32G32B32A32_SFLOAT";
    30.         cameraMatA.mainTexture = cameraA.targetTexture;
    31.     }
    32. }
    33.  
     
  2. glgamesforfun

    glgamesforfun

    Joined:
    Apr 13, 2021
    Posts:
    149
    If you want to assign targetTexture.format a RenderTextureFormat, then you cannot use a string.
    Code (CSharp):
    1. cam.targetTexture.format = RenderTextureFormat.RGB111110Float; // a format that is defined
    Hope this helps :)
     
  3. Jekirutu

    Jekirutu

    Joined:
    Jun 10, 2019
    Posts:
    14
    Thank you for your reply, but this solution gives me the following error:

    Setting color format of already created render texture is not supported!
    UnityEngine.RenderTexture:set_format (UnityEngine.RenderTextureFormat)
    PortalViewAdjustment:Start () (at Assets/Scripts/Player system/PortalViewAdjustment.cs:29)​

    Have I done something wrong?
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,546
    Jekirutu likes this.