Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Create lightmaps at runtime

Discussion in 'Editor & General Support' started by klad, Aug 28, 2012.

  1. klad

    klad

    Joined:
    Jul 13, 2011
    Posts:
    17
    Hello!

    I am developing a simple 2D puzzle game. I would like to give the user the option to design their own levels, so i have built a simple level editor, so they can upload play with their levels.

    The game comes with many levels made by me, and they look pretty nice, as i have a single unity scene for each level, and i've been able to set up the lights, and bake the lightmaps easily into the scene.

    My problem comes when i want the levels made with my level editor to have a decent lightning. As for now, my level editor only generates a simple xml that contains the necessary information to instanstiate all the objects at runtime ( walls, enemies, objects, etc.. ), and show the level as it was designed. Applying lightmaps to these levels is a whole different story thought. How i am supposed to do that?

    I can let the user place lights using the editor, but, how can i make it so i can bake the lightmap into that level? Dynamic lights is not an option, as i would like to have shadows on android/iphone, and as far as i know, that is not supported.

    The only soultion i've come up with, is to generate a .unity instead of an xml file ( don't really know if that is possible, by the way ), and somehow apply a process to that scene that bakes the lights into a lightmap and applies it. Is that even possible, or i'm daydreaming?

    Do you guys know any other way to achieve what i want to do?

    Thanks in advance!
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    From my point of view, this is not possible at all. Baking can only be done in the editor. Unity 4 comes with realtime shadows for mobiles, that's about the only way I can imagine.
     
  3. klad

    klad

    Joined:
    Jul 13, 2011
    Posts:
    17
    Okay, let's forget about runtime then. Looking for a workaround, i thought of the following:

    1.- Imagine there is a server somewhere, that receives the .xml file with the information of the designed level from the level editor. That server is made with unity, so he can create a scene, and save it as a unity file. ( That can be done using EditorApplication class ).

    2.- The created unity file has all the objects at his correct place, the lights correctly placed, so the only thing left to do is to bake the lightmap. Is there a way to do this automatically? Something like a batch process that receives a .unity file and automatically bakes and applys a lightmap to a scene, that would do the trick! Basically i want the editor to do the Window-->Lightmapping-->Bake scene on its own, how to tell him that??

    Thanks for your help!
     
  4. MADmarine

    MADmarine

    Joined:
    Aug 31, 2010
    Posts:
    627
  5. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    If the Unity editor is open, you have everything loaded, you can start the lightmap baking with a script: Lightmapping.
    Though, it is theoretically possible to do that, it is a huge amount of tricky work. Good luck with it! I wouldn't want to do that :)