Dev Snippets

UE4 4.15 Selective Light Baking

By on May 1, 2017

We heavily rely on sublevels to compartmentalize the different zones in our game. Unfortunately, the default light baking functionality doesn’t really accommodate this as baking from a level invalidates the lighting for all sublevels, even if they’re turned off.

Surprisingly, selective lightbaking was pretty easy to add in (the feature was already there, and we just had to expose it).

So we have multiple sublevels inside of a master level. Each sublevel has its own bake lighting inside of it. Most sublevels are only visible by themselves but we do have two sublevels that are both visible at the same time.

We rolled the functionality into an editor blueprint that our artists can use so that they can bake two sublevels together, one sublevel, etc without invalidating the lightbake.

There’s still some minor bugs (iirc, the PRT volume sample settings weren’t being respected correctly) but it works enough for our use case. If you’re interested, integrate the git patch listed at the bottom.

Then call this function to build your lighting and pass in a FLightingBuildOptions object:
FEditorBuildUtils::EditorBuild(GetWorld(), FBuildOptions::BuildLighting, /*This is of type FLightingBuildOptions */ MyBakeOptions , bAllowLightingDialog);

YMMV, but the option that we use stably is MyBakeOptions.bOnlyBuildSelectedLevels = true & we populate MyBakeOptions.SelectedLevels with the list of sublevels we want to build. Just be sure that the levels are visible and loaded. For automation purposes, we store references in our lightbaker tool to the levels with TAssetPtr<ULevel> references.



This site uses Akismet to reduce spam. Learn how your comment data is processed.