In untiy 2018.2.16, I use code like that to save lightprobes as an asset and in play mode i can change lightmap and lightprobes to change room state without load or unload scenes.
var probes = Object.Instantiate(LightmapSettings.lightProbes);
AssetDatabase.CreateAsset(probes, "Assets/Scenes/Room/XXXX/LightProbes.asset");
roomSceneData.LightProbes = probes;
but in unity 2019.3.8f1, it’s not work.Because unity now can not load Lightprobes.asset data. it’s just empty.
hope anyone have some solutions or workround or it’s just a bug.
I just tested this and it still works. Do you get any errors in the console? Have you tried opening the asset with a text editor to see if there’s any data in it?
I’ve also encountered issues with dynamically loading Light Probes in 2019.3 and onward, which is why the current project is locked to Unity 2019.2.
I’ve written a custom Lighting Manager that saves references to lightmaps and all the other necessary information to reconstruct the lighting in the scene on button press. That of course includes Light Probes. When some currently baked lighting is saved, I simply create a copy of the LightmapSettings.lightProbes object, save it and call it a day. In 2019.3 onward, saving the lightProbes object also works (the data is stored), but when loading, no Light Probe data is applied.
There’s two aspects to this that I don’t understand. Without knowing what happens under the hood, it appears as if Unity goes through all the LightProbes objects in the scene and synchronizes them to the currently baked lighting (which at time of loading lighting via my LightingManager can be none) as a result of the latest multi-scene Light Probe updates. Either that, or when there’s no lighting currently baked, the LightProbes object in LightmapSettings is null, so I can’t set any data in it, and the LightmapSettings object refuses to accept a new LightProbes object. The former is backed by the saved LightProbes object returning no data after the scene (where the data is stored) is reloaded, despite it being written to the file. The latter is backed by the whole thing magically working when some lighting is currently baked and I try to load over it via my LightingManager.
Looking at @laurent-h 's lightmap switching tool for 2019.3, I see that they’ve resorted to saving Light Probe coefficients rather than the whole object, and reconstruct the object upon loading. I’ve also tried to rewrite that part of my LightingManager to do exactly that, but again, upon loading, the LightmapSettings.lightProbes object is null when no lighting is baked.
In trying to counter that, I’ve also tried the several ways C# offers to create a LightProbes object myself to fill that with data and put the whole thing where it needs to be, but as a constructorless class I don’t see a (dirty or clean) way of doing it from C#-land. I’ve stopped my investigations short of putting all the data to be saved into ScriptableObjects saved into files, as I’m trying to avoid having a bunch of files to manage.
These were my observations trying to get it to work in 2019.3 and 2019.4. I’m interested in upgrading to 2019.4 for the UX improvements and so on, but don’t really see a way of it being viable right now.
Hi! I in fact didn’t notice the other branches in the repo, but unfortunately it’s not helping. I’ve again investigated the issue (by saving and loading SphericalHarmonicsL2[ ] instead of the whole LightProbes object) and am again met by LightmapSettings.lightProbes being null when there’s currently no baked lighting existing and I’m trying to access LightmapSettings.lightProbes.bakedProbes to set my previously saved SphericalHarmonicsL2[ ]. The SphericalHarmonicsL2 array definitely holds the data at time of loading, I just can’t put it where it needs to be. So no dice unfortunately.
I’ll not bore you with my custom LightingManager, since it’s implemented in practically the same way as your solution (there are only so many ways to approach this :)). I only didn’t make the separation of lighting scenes and geometry scenes and reconstruct the light GameObjects upon loading the lighting scenario, and don’t save all the data in ScriptableObject assets. But that should have no implications on LightmapSettings.lightProbes being null when nothing is baked as far as I can see.
I has the same problem,in unity2019.3.7f1。
i get LightmapSettings.lightProbes is null。
public class LProbeData: ScriptableObject
{
public UnityEngine.Rendering.SphericalHarmonicsL2[] lightProbes;
}
i put save scene’s LightProbes to Resources Folde,
when create Empty Scene to Load .
public class LoadProbes : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
// put save LProbeData to Resources Folder
var bakedProbes = Resources.Load<LProbeData>("maincity_probes");
Debug.Log(LightmapSettings.lightProbes); // = Null
if(bakedProbes != null && LightmapSettings.lightProbes != null)
LightmapSettings.lightProbes.bakedProbes = bakedProbes.lightProbes;
}
// Update is called once per frame
void Update()
{
}
}
Nope, we stuck with 2019.2 in the end, since we weren’t in dire need of an upgrade. But Magic Lightmap Switcher from the Asset Store seems to provide a way to do it now. Haven’t tested it myself, but it looks a lot like my solution, only with blending and with support for more modern Unity versions. And much more polished of course.