Code Sample: Lightmapping code for prefabs in Unity*

ID 671667
Updated 8/17/2018
Version Latest
Public

author-image

By

File(s): Download
License: Intel Sample Source Code License Agreement
Optimized for...  
OS: Windows® 10
Hardware: N/A
Software:
(Programming Language, tool, IDE, Framework)
C#, Unity*
Prerequisites: Familiarity with the Unity’s C# scripting. Unity 5 or beyond installed and configured.

Introduction

Attach this script as a component to any prefab you might want to lightmap. From the editor window inside Unity you can setup a scene with proper lighting and position your prefabs inside the scene as per your requirements. In the Editor go to Assets-> Bake Prefab Lightmaps which will generate the baked lighting and save it in any prefabs with the script. You can now spawn in different scenes with the baked lighting.

Get Started

Download the code from GitHub* and read Optimization for Unity* Software and Virtual Reality: Run-Time Generated Content for a better understanding of how to prefab you might want to lightmap.

References

https://docs.unity3d.com/ScriptReference/LightmapData.html

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

Updated Log

Created July 17, 2018