Search Unity

LightProbes.needsRetetrahedralization is called only once?

Discussion in 'Editor & General Support' started by ReadyPlayGames, Oct 23, 2021.

  1. ReadyPlayGames

    ReadyPlayGames

    Joined:
    Jan 24, 2015
    Posts:
    49
    The reference says:

    If you are loading multiple scenes which each contain additional light probe data, you should wait for the corresponding number of needsRetetrahedralization events before retetrahedralizing...For example, if you were to additively load five scenes which each contain light probe data, you should wait for all five needsRetetrahedralization events before calling LightProbes.Tetrahedralize or LightProbes.TetrahedralizeAsync.
    This makes sense, but the event seems to trigger only once. I made a script (You'll need scenes with lightprobes in them added to the build settings):

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6. public class LightProbesNeedingUpdates : MonoBehaviour {
    7.  
    8.     public string[] additiveSceneNames = new string[]{"AdditiveLightprobes1", "AdditiveLightprobes2" };
    9.     public int scenesNeedingRetetrahedralization;
    10.  
    11.     public void TetrahedralizationCompleted(){
    12.         Debug.Log("Tetrahedralization Completed!");
    13.     }
    14.  
    15.     public void NeedsTetrahedralization(){
    16.         Debug.Log("Calling NeedsTetrahedralization");
    17.         scenesNeedingRetetrahedralization++;
    18.         if(scenesNeedingRetetrahedralization >= additiveSceneNames.Length){
    19.             scenesNeedingRetetrahedralization = 0;
    20.             LightProbes.Tetrahedralize();
    21.         }
    22.     }
    23.  
    24.     private void OnEnable() {
    25.         LightProbes.needsRetetrahedralization += NeedsTetrahedralization;
    26.         LightProbes.tetrahedralizationCompleted += TetrahedralizationCompleted;
    27.     }
    28.     private void OnDisable() {
    29.         LightProbes.needsRetetrahedralization -= NeedsTetrahedralization;
    30.         LightProbes.tetrahedralizationCompleted -= TetrahedralizationCompleted;
    31.     }
    32.  
    33.     private void Update() {
    34.         if(Input.GetKeyDown(KeyCode.Z)){
    35.             LoadAdditiveScenes();
    36.         }
    37.         else if(Input.GetKeyDown(KeyCode.X)){
    38.             UnloadScenes();
    39.         }
    40.     }
    41.  
    42.     public void LoadAdditiveScenes(){
    43.         scenesNeedingRetetrahedralization = 0;
    44.         StopAllCoroutines();
    45.         StartCoroutine(LoadAdditiveScenesCO());
    46.     }
    47.     // To simulate different loading times, we're faking it.
    48.     private IEnumerator LoadAdditiveScenesCO(){
    49.         for (int i = 0, length = additiveSceneNames.Length; i < length; i++) {
    50.             SceneManager.LoadSceneAsync(additiveSceneNames[i], LoadSceneMode.Additive);
    51.             yield return new WaitForSeconds(0.5f);
    52.         }
    53.     }
    54.  
    55.     public void UnloadScenes(){
    56.         for (int i = 0, length = additiveSceneNames.Length; i < length; i++) {
    57.             SceneManager.UnloadSceneAsync(additiveSceneNames[i]);
    58.         }
    59.     }
    60. }
    Am I doing this incorrectly?
     
    Last edited: Oct 26, 2021
    KarlKarl2000 likes this.
  2. happyfirecn

    happyfirecn

    Joined:
    Dec 28, 2016
    Posts:
    11
    Test in Unity2020.3.46f, it is OK.
     
    KarlKarl2000 likes this.