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 on change Bloom intensity with Cinemachine + Post Processing

Discussion in 'Scripting' started by Octoverse, May 17, 2020.

  1. Octoverse

    Octoverse

    Joined:
    Oct 14, 2018
    Posts:
    25
    Hello everyone!

    I use Unity 2019 and ever use the package manager to give Cinemachine and Post Processing (v2)

    I'm trying to access the Bloom effect and change its intensity value.

    I don't get errors in Visual Studio or Unity on standby, but when I go to test, the Unity gaves me this error:

    My code is like this:
    Code (CSharp):
    1.     public CinemachinePostProcessing PostFX;
    2.  
    3.     void Start()
    4.     {
    5.         var bloom = PostFX.GetComponent<Bloom>();
    6.         bloom.intensity.value = 30f;
    7.     }
    Visual Reference:


    Any idea to fix this and access the bloom intensity parameter?

    Thanks in advance
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,724
    I think you may have accidentally omitted the error!
     
  3. Octoverse

    Octoverse

    Joined:
    Oct 14, 2018
    Posts:
    25
    Oh, is true! Sorry, friend!

    Here:
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,724
    It looks like Bloom is not a component so you'll need to access it in as different way than using the GetComponent<> method directly. It looks like it might be part of the Cinemachine Post-Process Volume component. So you might have to get that first. I don't know enough about the Cinemachine API off the top of my head to know exactly what the path to the Bloom object is.
     
  5. Octoverse

    Octoverse

    Joined:
    Oct 14, 2018
    Posts:
    25
    Thanks to answer, friend! I'll to try this now and back here with the same or with a solution. I hope the solution, really haha

    Hugs!
     
    PraetorBlue likes this.
  6. Octoverse

    Octoverse

    Joined:
    Oct 14, 2018
    Posts:
    25
    Hi. Thanks again. i got it make! Your answer opened my vision. I'll leave the solution for who comes later.

    To access Post Process Volume params, normally we use:
    Code (CSharp):
    1. camera.profile.TryGetSettings(out param);
    with Cinemachine, need access with m_Profile, not profile :)

    The solution is very simple (at least on Unity 2019):
    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine.PostFX;
    3. using UnityEngine.Rendering.PostProcessing;
    4.  
    5. public class MyClass : MonoBehaviour
    6. {
    7.         public CinemachinePostProcessing PPvCam;
    8.         private Bloom bloom;
    9.  
    10.         void changePostFXParams()
    11.         {
    12.                 PPvCam.m_Profile.TryGetSettings(out bloom);
    13.                 bloom.enabled.value = true;
    14.                 bloom.intensity.value = 10f;
    15.         }
    16. }

    in this case, intensity is this param (in yellow):

    The params have de same name of the inspector, then just type bloom variable dot param name

    Other example to help any that comes later:

    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine.PostFX;
    3. using UnityEngine.Rendering.PostProcessing;
    4.  
    5. public class MyClass : MonoBehaviour
    6. {
    7.         public CinemachinePostProcessing PPvCam; //my cinemachine virtual camera
    8.  
    9.         private Bloom bloomParam; //my bloom fx
    10.         private ColorGrading colorGradeParam; //my color grading fx
    11.         private DepthOfField dofParam; //my depth of field fx
    12.  
    13.         void changePostFXParams()
    14.         {
    15.                 //Get the post-processing volume params from cinemachine camera
    16.                 PPvCam.m_Profile.TryGetSettings(out bloomParam);
    17.                 PPvCam.m_Profile.TryGetSettings(out colorGradeParam);
    18.                 PPvCam.m_Profile.TryGetSettings(out dof);
    19.  
    20.                 //Set Active
    21.                 bloomParam.enabled.value = true;
    22.                 colorGradeParam.enabled.value = true;
    23.  
    24.                 //Set Bloom Values
    25.                 bloomParam.intensity.value = 5f; //Intensity
    26.                 bloomParam.color.value = Color.red; //Color
    27.  
    28.                 //Set Color Grading Values
    29.                 colorGradeParam.colorFilter.value = Color.blue; //Color Filter
    30.  
    31.                 //Set Depth of Field values
    32.                 dofParam.focusDistance.value = 1f; //focus Distance
    33.         }
    34. }

    Thanks and per your atention!
     
    Jh2556 and PraetorBlue like this.
  7. rocco_wu

    rocco_wu

    Joined:
    Jul 27, 2018
    Posts:
    3
    I'm trying to do a similar method in my 2020.1.1f URP project but I seem to not be able to get the bloom component. I'm using Cinemachine and under the virtual camera component, there are extensions and one of the extensions are the post-processing volumes where I can access bloom but I can't access it in bloom? What should I do?
     
  8. Jh2556

    Jh2556

    Joined:
    Sep 29, 2014
    Posts:
    18
    @Octoverse OMG thank you!! Why was this solution so hard to find, this is exactly what I've been looking the past 2 hours for haha

     
    Octoverse likes this.
  9. Octoverse

    Octoverse

    Joined:
    Oct 14, 2018
    Posts:
    25
    you're welcome!