How can I switch between multiple directional lightmaps?

Hello,

I’m a newbie in using Unity and set up a scene within which is placed a gameobject, that can be hidden by pressing a key on the keyboard.

The problem is I have a lightmap, that must be updated after the object is hidden (no object means no shadow).

When I bake a dual lightmap it’s no problem to load my lightmaps from the resources folder to the lightmapData Array. I just load the lightmapFar and the lightmapNear.

But when I bake a directional lightmap it doesn’t work. Maybe the problem is that the attributes lightmapFar and lightmapNear aren’t available?

Is there any possibility to load the two maps (color and scale) which I receive by baking a directional lightmap into the array?

I hope the description of my problem isn’t to confusing…

Thanks a lot!

why it’s not possible ? I often play with the lightmap. I could probably help if you say what is the problem ? :wink:

One of my multiple answer on the dynamic lightmap loading : Access use lightmap property using script - Unity Answers

This is my code, which works perfectly with dual lightmaps:

function ChangeLightmap (){
var lightmapData = new LightmapData[1];
lightmapData[0] = new LightmapData();
var mapdata: LightmapData = new LightmapData();

if(LightmapThron){
	lightmapData[0].lightmapFar = Resources.Load( "Thronsaal_01/LightmapColor-0", typeof(Texture2D)) as Texture2D;
	lightmapData[0].lightmapNear = Resources.Load( "Thronsaal_01/LightmapScale-0", typeof(Texture2D)) as Texture2D;
 	Debug.Log(lightmapData[0].lightmapFar);
}
else{
	lightmapData[0].lightmapFar = Resources.Load( "Thronsaal_01/LightmapColor-1", typeof(Texture2D)) as Texture2D;
	lightmapData[0].lightmapNear = Resources.Load( "Thronsaal_01/LightmapScale-1", typeof(Texture2D)) as Texture2D;
}

LightmapSettings.lightmaps = lightmapData;

}

But when I bake the same scene with directional lightmapping I get a LightmapColor and a LightmapScale instead of LightmapFar and LightmapNear and I just don’t know how to import them via code. When I run the code the Maps menue is cleared and only two empty slots remain.

Thanks for your reply!