Search Unity

Question How to change cubemap on reflection probe in custom mode at runtime?

Discussion in 'High Definition Render Pipeline' started by iamarugin, Dec 21, 2019.

  1. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    883
    I have reflection probe in Custom mode. I want to swap cubemap on it at runtime. What should I do? I tried probe.bakedTexture = newCubemap; but it doesn't work.
     
  2. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    883
  3. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    883
  4. laurent-h

    laurent-h

    Joined:
    Sep 29, 2016
    Posts:
    78
    Hi,
    Here is a code snippet that should help you achieve that.
    Note that the HighDefinition namespace is only valid for Unity 2019.3 and HDRP 7.1+ versions

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering.HighDefinition;
    3.  
    4. public class SwitchToCustom : MonoBehaviour
    5. {
    6.     public Texture texture;
    7.    
    8.     void Start()
    9.     {
    10.         var probe = gameObject.GetComponent<HDAdditionalReflectionData>();
    11.         probe.SetTexture(ProbeSettings.Mode.Custom, texture);
    12.         probe.mode = ProbeSettings.Mode.Custom;
    13.     }
    14. }
     
  5. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    883
    Hi, thank you! For some reason I missed this method. It works like a charm.
     
    laurent-h likes this.