Skip code while cooking

During cooking (during BuildCookRun), our maps are loaded, cooked, and saved out. Some of our maps, however, have code which programmatically includes other levels as sublevels. These maps are nearly empty in their natural form. They have some basic code in the level blueprint to configure something in our GameState class (in C++). Once the match is waiting to start, our GameState class uses this configuration to generate a map (by loading levels) using the configuration. I’d like to skip doing this when cooking.

I can tell our code is getting called (because I have some logging code in there and it shows up in the build log). Our code is in HandleMatchisWaitingToStart and HandleMatchHasStarted. So it appears they get called during cooking.

Is there some global state that I can check to determine that cooking is happening? I had hoped that IsRunningCommandlet() would work, but it seems to be false.

It turns out that IsRunningCommandlet() does work to exclude cooking. The code it encloses won’t run when any other commandlet is run, which may not be desired.

There is also a global, GIsCookerLoadingPackage, which is set to true when packages are being loaded/saved for cooking.

1 Like

There is also IsRunningCookCommandlet() which is useful, mostly to load all assets that must be cooked/packaged if you are not referencing them.