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. Dismiss Notice

No way to bake occlusion culling from script?

Discussion in 'Scripting' started by FabrizioSpadaro, Feb 28, 2016.

  1. FabrizioSpadaro

    FabrizioSpadaro

    Joined:
    Jul 10, 2012
    Posts:
    287
    Hi guys, my question is quite simple i have a procedural generated scene,so i can't press the bake button in the occlusion culling windows, is there any way to bake it from code?
     
    BlackPete likes this.
  2. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    Wondering the same thing. Been searching/googling forever, and haven't found anything satisfactory yet.

    I too am dealing with assets that only exist in memory, so applying static settings and baking stuff is tricky.
     
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I would suggest procedurally generating the scene in edit mode, then save the scene out. That way you can bake to your hearts content.

    Baking a scene that is generated at runtime doesn't really make any sense. So it doesn't surprise me its not possible.
     
    TaleOf4Gamers and FreeFly90 like this.
  4. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    "Runtime" is a bit of a misnomer. Picture a Unity client that receives assets from an external source.

    I'm even having trouble thinking of a way to make this work as part of an export plugin from some 3rd party software like Max, Maya, etc. A pipeline is written to import from these files, apply the static flag to them, bake whatever, then turn them into an asset bundle as an automated process.

    All of that needs to be done using a script.
     
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    So if its not at runtime, what is wrong with using editor scripting?

    Its not straight forward, but Unity does provide all the tools you need to build a fully automated pipeline.

    Create a new scene
    https://docs.unity3d.com/ScriptReference/SceneManagement.EditorSceneManager.html

    Import your assets
    https://docs.unity3d.com/ScriptReference/AssetPostprocessor.html
    https://docs.unity3d.com/ScriptReference/AssetDatabase.html

    Bake lightmapping
    https://docs.unity3d.com/ScriptReference/Lightmapping.html

    Bake occlusion
    https://docs.unity3d.com/ScriptReference/StaticOcclusionCulling.html

    Create an asset bundle
    https://docs.unity3d.com/ScriptReference/BuildPipeline.html
     
  6. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    Thanks. I didn't know about StaticOcclusionCulling, so that's really useful. It's unfortunate it's editor only, but it makes sense that if the baking tool exists only in the Editor, and not in some DLL or plugin that can be packaged with the client, then that's a limitation I'll have to live with.
     
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    For 99% of users, baking outside of the editor doesn't make that much sense. Which is probably why its editor only.

    That said there is nothing stopping you shipping an editor extension to your client, assuming they can obtain appropriate licenses to run Unity.
     
  8. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    I have been wondering about this too.
    In my scene I have items which need to be activated before for the bake (i.e. objects which need to be active for the Realtime GI emission calculations). Every now and then I forget to enable these items and after a 4 hr bake, I realized I forgot to enable them!
    Creating the editor script to run the bake can ensure these item are enabled when doing the bake from the editor script). Then disabled again after the bake.
     
  9. SkyArchitect

    SkyArchitect

    Joined:
    Jan 13, 2016
    Posts:
    4
    How do I obtain the license to add Umbra occlusion culling to my build game?
    I got a procedural dungeon generation in my game. Every time the player enters the dungeon it will be different and I can't add millions of dungeons into my game build.
    Thank you.
     
    PNUMIA-Rob likes this.
  10. XJDHDR

    XJDHDR

    Joined:
    Mar 31, 2020
    Posts:
    19
    There is no license that lets you bake Umbra's OC data at runtime. It has to be done during development. If your game is procedurally generated such that you need runtime OC, you can't use Umbra.

    My only suggestion would be to either write up your own runtime OC implementation or see if someone has provided their own implementation either in the Asset store or elsewhere. I was working on one idea using RaycastCommand for my project but it's on hold until my game is further along in development: https://github.com/XJDHDR/BethBryo_...dAndUnsorted/OcclussionCullingLosDetection.cs

    I have also heard about ways to use the GPU to determine when objects are behind others but I'm not too familiar with those.