I saw some old threads which said that lightmapping information is not included in asset bundles, even when you track dependencies. I tried it myself and it looks like it’s still the case. My maps are downloaded as assetbundles and I would (really) like lightmapping/light probe information to still be there…
Anyone had experience with this?
What do you mean with ‘lightmap information’?
Lightmaps are stored on the meshes in the scene, they are just the texture on UV1 (for example relevant when you do raycasting and want to get the brightness at a point). So that information is present by default and switching them at runtime never has been a problem. You just had to do it yourself.
Lightprobes got added somewhat in 4.0 and 4.1 from what I recall.
Unluckily I fear that I am not sure on the 4.1.x current state on whats present and can be accessed from scripting. That being said: whatever is in normal builds is in scenes built to asset bundles too.
Neither of the two informations transfers with prefabs in asset bundles but I don’t think thats what you are after as you talk about maps in ASBs which means streaming scenes.
I just meant that lightmapping isn’t imported along with the rest of the AssetBundle. After some more reading I realize that. I’m trying now to load it ‘manually’. What I’m doing is adding a component to my main asset with a script which holds the lightmapping information - the 2 textures - the near and far lightmapping textures and the lightmapping mode.
When I download the assetBunddle, I load the main asset and save the lightmapping information from that component. Then I go through the renderers and assign them (I create an empty lightmap in the scene before hand so my lightmap array size is 1).
Here is the code:
I think now the issue is that of the textures, even though I see them in the inspector they still come up as ‘null’, I guess I need to save them somehow, which is something I am looking into now. If you have any tips on that I would highly appreciate it
EDIT: *So I can avoid this whole issue by using streamed scenes ? (for both lightmapping and lightprobes??)
public Texture2D farColor;
public Texture2D nearScale;
// Use this for initialization
void Start ()
{
StartCoroutine(DownloadAndCache(mapName));
}
IEnumerator DownloadAndCache (string mapName)
{
string originialBundlePath = BundleURL;
// Wait for the Caching system to be ready
while (!Caching.ready)
{
yield return null;
}
// Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
//Map---------------------------------------------------------------------------------------------------------------------------------------------
string mapBundlePath = originialBundlePath + mapName + ".unity3d";
using(WWW www = WWW.LoadFromCacheOrDownload (mapBundlePath, version))
{
while( !www.isDone )
{
yield return null;
}
yield return www;
if (www.error != null)
{
throw new Exception("WWW download had an error:" + www.error);
}
AssetBundle bundle = www.assetBundle;
if (AssetName == "")
{
GameObject mapToInstantiate = Instantiate(bundle.mainAsset) as GameObject;
farColor = mapToInstantiate.GetComponent<LightmapInfo>().farLightmapTextureColor;
nearScale = mapToInstantiate.GetComponent<LightmapInfo>().nearLightmapTextureScale;
LightmapData ourLightmap = new LightmapData();
ourLightmap.lightmapNear = nearScale;
ourLightmap.lightmapFar = farColor;
LightmapSettings.lightmapsMode = mapToInstantiate.GetComponent<LightmapInfo>().lightmapMode;
LightmapSettings.lightmaps[0] = ourLightmap;
LightmapSettings.lightmaps[0].lightmapFar = farColor;
LightmapSettings.lightmaps[0].lightmapNear = nearScale;
Renderer[] renderers = mapToInstantiate.GetComponentsInChildren<Renderer>();
for(int i = 0; i<renderers.Length; i++)
{
renderers[i].lightmapIndex = 0;
}
for(int j = 0; j<renderers.Length; j++) //just for checking, the textures are still null
{
print (renderers[j].lightmapIndex + " " + LightmapSettings.lightmaps[0].lightmapNear + " " + LightmapSettings.lightmaps[0].lightmapFar);
}
}
else
{
Instantiate(bundle.Load(AssetName));
}
// Unload the AssetBundles compressed contents to conserve memory
bundle.Unload(false);