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

Question Cannot set PostProcessing to enabled on URP an instantiated Cameras

Discussion in 'Universal Render Pipeline' started by Spacedawg, Sep 9, 2021.

  1. Spacedawg

    Spacedawg

    Joined:
    Mar 30, 2015
    Posts:
    3
    using 2019 LTS and 2021.1.19 in URP mode

    Greetings, I'm currently using a beta headmount display (tilt5) devkit that does not instantiate it's left/right eye cameras until runtime.

    If i set up a PostProcessing Volume, and then enter play mode, select the newly instantiated Left and Right Eye Cameras, and check the post processing checkbox, it works... but no good for builds...

    I scripted 3 methods of hacking this post processing flag on:

    1 modify the script listed in the makers docs to add...
    Code (CSharp):
    1.  UnityEngine.Rendering.Universal.UniversalAdditionalCameraData uac = eyeCamera.GetComponent<UnityEngine.Rendering.Universal.UniversalAdditionalCameraData>();
    2.         uac.renderPostProcessing = true;
    ...to each eye camera after instantiation
    2 make a new script to find camera game objects by name, find camera component, and
    UnityEngine.Rendering.Universal.UniversalAdditionalCameraData inside that and uac.renderPostProcessing = true;
    3 alter the script attached to URP cameras [project folder]\Library\PackageCache\com.unity.render-pipelines.universal@7.3.1\Runtime\UniversalAdditionalCameraData.cs to force post processing variable to true...
    Code (CSharp):
    1. [SerializeField] bool m_RenderPostProcessing = true;
    all of these methods work in play mode IF and ONLY IF I click on the left and right eye cameras in the hierarchy prior to execution of the scripts in methods 1 and 2, and for method 3 as soon as the left and right cameras are clicked post processing is checked and it works... not before

    So again, I can't use these for a build, because instantiated cameras have this Schrodinger's Cat like behavior, where they need to be highlighted in the hierarchy in play mode before the content of UniversalAdditionalCameraData.cs is active for the GameObject.

    PostProcessing is only enabled by default when i look at the check box and the scripted variable to enable uac.renderPostProcessing on the cameras is null reference until i open the cameras on the hierarchy
     
  2. Spacedawg

    Spacedawg

    Joined:
    Mar 30, 2015
    Posts:
    3
    I solved it by forcing UniversalAdditionalCameraData onto the cameras using AddComponent

    Code (CSharp):
    1.     void EnableURP_PP()
    2.     {
    3.  
    4.         GameObject CamLeft = GameObject.Find("Left Eye Camera");
    5.         CamLeft.AddComponent<UnityEngine.Rendering.Universal.UniversalAdditionalCameraData>();
    6.         UnityEngine.Rendering.Universal.UniversalAdditionalCameraData uacL = CamLeft.GetComponent<Camera>().GetComponent<UnityEngine.Rendering.Universal.UniversalAdditionalCameraData>();
    7.         uacL.renderPostProcessing = true;
    8.  
    9.         GameObject CamRight = GameObject.Find("Right Eye Camera");
    10.         CamRight.AddComponent<UnityEngine.Rendering.Universal.UniversalAdditionalCameraData>();
    11.         UnityEngine.Rendering.Universal.UniversalAdditionalCameraData uacR = CamRight.GetComponent<Camera>().GetComponent<UnityEngine.Rendering.Universal.UniversalAdditionalCameraData>();
    12.         uacR.renderPostProcessing = true;
    13.     }
     
    iside2000s_unity likes this.
  3. ProfPivec

    ProfPivec

    Joined:
    Sep 21, 2012
    Posts:
    21
    Thanks for Sharing. Helped a lot, more than Unity's lack of documentation on URP.
    Again, thank you.