LightProbes.bakedProbes can't change

Question:
I saved multiple lightprobes objects, set one to lightmapsetting.lightprobes and modified bakedProbes. But when I switched the lightmapsetting.lightprobes object, I found that its bakedProbes were reset to the initial value and could not be modified through direct assignment.

Solution:
We can only modify the value of lightmapsetting.lightprobes.bakedprobes, so we need to save an additional spherical harmonic coefficient (this is the modified value at runtime). When lightmapsetting.lightprobes switches objects, use the saved spherical harmonic coefficients to modify the current lightmapsetting.lightprobes.bakedprobes.

Is there any other way to modify it?

Just trying to understand what you are attempting: You want to permanently modify coefficients stored in a LightProbes object on disk? Or only in memory

Only in memory.
I was trying to modify the spherical harmonic coefficients at runtime, but I found that once an operation such as “lightmapsetting.lightprobes = currentLightProbes” is performed, the data of currentLightProbes will be restored to its initial value.currentLightProbes is a LightProbes object that I serialize and store before running.

I see, so you are getting different results if you try to swap out the entire LightProbes object (LightmapSettings.lightProbes) vs if you just try to swap out the baked coefficients (LightmapSettings.lightProbes.bakedProbes). That sounds like a bug to me, so you might want to file a bug report if this is hindering you.

Which version of Unity are you on? We refactored the LightProbes system quite a bit in 2022 and then again in 2023. Might be worth checking if this reproduces on older versions.

One thing that might be worth trying (I think this mattered for old versions): After you swap out LightmapSettings.lightProbes, try calling this https://docs.unity3d.com/ScriptReference/LightProbes.Tetrahedralize.html and seeing if it makes a difference

My Unity Version is 2020.3.44f1.
Okay, although my project cannot be upgraded, I will try it in Unity 2023.
The errors I encountered were mainly related to the data of bakedProbes, there was no problem with the data of the tetrahedron.

I’m aware. On some versions of Unity, Tetrahedralize also affects the probe SH coefficients.

I tried this, but nothing changed.

SphericalHarmonicsL2[] beforeSH = data.lightProbes[0].bakedProbes;
LightmapSettings.lightProbes = data.lightProbes[0];
SphericalHarmonicsL2[] aftherSH = data.lightProbes[0].bakedProbes;

In this way, the values of beforeSH and afterSH are different.