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.

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:
    817
    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:
    817
  3. iamarugin

    iamarugin

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

    laurent-h

    Joined:
    Sep 29, 2016
    Posts:
    77
    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:
    817
    Hi, thank you! For some reason I missed this method. It works like a charm.
     
    laurent-h likes this.