Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by misterPantoni · Nov 30, 2016 at 03:02 PM · lightmappingassetbundles

Unity 5 lightmapped scene assetbundle problem

Hey there,

i am having troubles loading an scene-assetbundle with lightmaps. Everything else works (loading bundles), but i can't find a solution to see lightmaps on my objects. I am building one assetbundle per scene, and load it with Scenemanager.loadAsync.

This is what it should look like (and how it looks if i load the scene the normal way, without assetbundles):

alt text

and this is what i get if i load my assetbundle:

alt text

the lightmaps somehow seem to be bundled in the assetbundle, if i load the bundle-scene in the editor and look at the lightmap-settings, i see the lightmaps are there - Unity just does not apply them to the objects.

Is this a bug or am i doing something wrong/do i need to do anything "special" to apply the lightmaps? Thanks in advance!

lightmaploading-should.jpg (46.1 kB)
lightmaploading-is.jpg (35.6 kB)
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image misterPantoni · Nov 30, 2016 at 03:03 PM 0
Share

Here is a screenshot of the lighting-inspector with the assetbundle loaded - the lightmaps are loaded, but not applied :/alt text

lightmaploading-inspector.jpg (32.9 kB)
avatar image tomekkie2 · Nov 30, 2016 at 04:00 PM 0
Share

I had the same problem a long time ago and then I included a "blind" lightmapped scene into the build and that helped. So it looked the hightmapping got stripped in some way. So I guess you could try the same or try to add some lightmaps into your starting scene.

avatar image misterPantoni tomekkie2 · Dec 01, 2016 at 07:50 AM 0
Share

thanks for your advice, unfortunately this did not change anything for me :/ When you had the error, was this already with the new U5 Beast Lighting System?

avatar image tomekkie2 misterPantoni · Dec 02, 2016 at 01:20 PM 0
Share

I had this error in Enlighten, i.e. the new U5 lighting system. I just have several projects like one below: http://virtualplayground.d2.pl/WebGL/ptg2015/galleries/galleries.php and it works in all of them.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by misterPantoni · Dec 02, 2016 at 11:04 AM

After a lot of tests and googeling around i found a working solution, although i am not totally happy with it:

If you store the lightmaps and the LightmapSettings for each renderer in a custom script, you can load the lightmaps on runtime. Look at this forum post and the sample project provided there, this is how i got it to work:

https://forum.unity3d.com/threads/problems-with-instantiating-baked-prefabs.324514/

The "bad" thing is, that now i need to have a duplicate of the lightmaps stored in my custom script - whenever i try to assign the lightmaps which are "in the scene" (and also after loading the assetbundle, at least in the editor i can see them), they somehow are not beeing loaded correcty by the renderers and i get wrong lightmap positions. So i have to store the lightmaps as extra texture and add them to the lightmap array to use them.

EDIT: The problems with the wrong index were just some indices i messed up - now i got it working the way i want it to, without duplicate Lightmaps. Here is the working script, just place it on the parent object of whatever is lightmapped in your scene you want to use as an assetbundle:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class SceneAssetBundleLightmaps : MonoBehaviour{
     [System.Serializable]
     struct RendererInfo{
         public Renderer     renderer;
         public int             lightmapIndex;
         public Vector4         lightmapOffsetScale;
     }
 
     [SerializeField]
     RendererInfo[]    m_RendererInfo;
 
     void Awake (){
         if (m_RendererInfo == null || m_RendererInfo.Length == 0)
             return;
         ApplyRendererInfo(m_RendererInfo);
     }
         
     static void ApplyRendererInfo (RendererInfo[] infos){
         for (int i=0;i<infos.Length;i++){
             var info = infos[i];
             info.renderer.lightmapIndex = info.lightmapIndex;
             info.renderer.lightmapScaleOffset = info.lightmapOffsetScale;
         }
     }
 
 #if UNITY_EDITOR
     [UnityEditor.MenuItem("Assets/Assign Scene Assetbundle Lightmaps")]
     static void GenerateLightmapInfo (){
         if (UnityEditor.Lightmapping.giWorkflowMode != UnityEditor.Lightmapping.GIWorkflowMode.OnDemand){
             Debug.LogError("ExtractLightmapData requires that you have baked you lightmaps and Auto mode is disabled.");
             return;
         }
         //UnityEditor.Lightmapping.Bake();
 
         SceneAssetBundleLightmaps[] prefabs = FindObjectsOfType<SceneAssetBundleLightmaps>();
 
         foreach (var instance in prefabs){
             var gameObject = instance.gameObject;
             var rendererInfos = new List<RendererInfo>();
             var lightmaps = new List<Texture2D>();
             
             GenerateLightmapInfo(gameObject, rendererInfos, lightmaps);
             
             instance.m_RendererInfo = rendererInfos.ToArray();
         }
     }
 
     static void GenerateLightmapInfo (GameObject root, List<RendererInfo> rendererInfos, List<Texture2D> lightmaps){
         var renderers = root.GetComponentsInChildren<MeshRenderer>();
         foreach (MeshRenderer renderer in renderers){
             if (renderer.lightmapIndex != -1)
             {
                 RendererInfo info = new RendererInfo();
                 info.renderer = renderer;
                 info.lightmapOffsetScale = renderer.lightmapScaleOffset;
                 info.lightmapIndex = renderer.lightmapIndex;
                 rendererInfos.Add(info);
             }
         }
     }
 #endif
 
 }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by mr_zog · Apr 26, 2018 at 07:53 AM

Using Unity 5.6.5p4 (64-bit)

Edit -> Project Settings -> Graphics -> Shader Stripping -> Lightmap Modes -> Set them to MANUAL and select the modes you use. Worked for us!

Credits go to: https://www.leegoonz.com/single-post/2016/07/10/Asset-bundle-with-Lightmap-packing-problem-How-to-solve https://docs.unity3d.com/540/Documentation/Manual/BuildingAssetBundles.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

59 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is Overlapping UVS a problem when creating for asset store? 0 Answers

Any way to stream 3D GameObjects on Unity Basic? 0 Answers

Asset bundles caching.IsversionCached() always returns false 1 Answer

How to get version of asset bundle file ? 0 Answers

Managing assetbundles (caching vs non-caching) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges