Is there a way to disable optimizations on a project without editing the build.cs file?

I’m able to disable optims on a specific project by adding OptimizeCode = CodeOptimization.Never to the build.cs file, but that file is checked into source control and used by everyone. Yeah, I could just check it out and keep the change locally, but that always runs the risk of accidentally submitting that for the whole team.

Is there a way to locally override this value, perhaps in a local ini file?

What’s the actual problem that you’re trying to solve?

Usually that would be controlled by selecting the right build configuration, either Debug or DebugGame. Debug is the optimization setting from your example and DebugGame narrows the non-optimized code to your game module and any non-engine plugins.

As a perforce user, for cases where I need a local edit and want to make sure it doesn’t get checked in I place it in a specific changelist that only exists to hold files that shouldn’t be checked in. I know that doesn’t work for everyone, but thought I’d put it out there.

Not really a specific problem to solve. I’m not sure what other information I can give. Maybe there’s a specific engine level plugin that I regularly work in or maybe I prefer to work on the dev config to get a better framerate but I want to have one or two specific game modules deoptimized for targeted debugging. There are a bunch of reasons why I might want to work in a different state than the default build configs.

And yes, I would of course just move the file to a do not submit CL in P4 and I’m careful to diff files before submitting and I’m unlikely to make changes to build.cs files often. This is obviously a workable solution, but something locally configurable would be safer which is why I’m asking.

Had to ask, a lot of people ask questions assuming that the solution they’re asking about is the solution to the problem they’re having when the solution is just something else entirely.

Maybe someone else will chime in with something, but as far as I’ve encountered it’s the build configuration or build.cs files. There might be some xml files around somewhere too, but they’ve got the same problem: they’d be in source control. You may be able to introduce new build configurations, one that you could check in safely but I don’t think it’s a straight forward process (and ultimately it may not be worth it depending on how often it changes).

Yeah, this lines up with what I’ve found so far too. Pretty sure this is the only method. Thanks for the reply, though.

There is a way to disable optimization on only the files that you’re working on. In Engine/Saved/UnrealBuildTool/BuildConfiguration.xml:

<?xml version="1.0" encoding="utf-8"?>
<Configuration xmlns="https://www.unrealengine.com/BuildConfiguration">
	<BuildConfiguration>
		<bUseAdaptiveUnityBuild>true</bUseAdaptiveUnityBuild>
		<bAdaptiveUnityDisablesOptimizations>true</bAdaptiveUnityDisablesOptimizations>
		<bAdaptiveUnityDisablesPCH>true</bAdaptiveUnityDisablesPCH>
	</BuildConfiguration>
</Configuration>
1 Like

Did some reading on this. Looks like this is doing something along the lines of figuring out what files you’re modifying and then removing them from the blob files and then once that’s done, it’s disabling optims on any files that are not in blob files.

If so, that’s useful and I’ll keep that in mind (even just for compile iteration time) but not quite what I was looking for. My general use case for something like this is a project that I frequently need to debug.

Thanks for the info, though. That’s a good trick.

If you want to disable code optimizations for specific modules without checking anything in (like when you edit the *.Build.cs file) then you can use this:

<DisableOptimizeCodeForModules></DisableOptimizeCodeForModules>

Edit: Apparently it’s <DisableOptimizeCode>, see @dbrespawn’s comment below.

See from TargetRules.cs source:

/// <summary>
/// List of modules to disable optimizations for
/// </summary>
[XmlConfigFile(Category = "ModuleConfiguration", Name = "DisableOptimizeCode")]
public string[]? DisableOptimizeCodeForModules = null;

This allows you to disable code optimizations for specific modules in your BuildConfiguration.xml in the Saved folder which isn’t checked in. I’m not sure what the format is for supplying arrays of strings in XML but if you figure it out please post it in this thread for others to learn.

For others reading this that might want a less hassle (and less modular) way of disabling optimizations @MagForceSeven had the best suggestion.

If you change your project’s build configuration to one of these then that overrides all optimizations on the project:
image

  • DebugGame Editor: Builds the Editor and your Game. Disables optimizations on your game’s code, but keeps Engine and Editor code optimized.
  • Debug Editor: I don’t recommend this one unless you’re doing hardcore editor debugging as it severely slows the Editor down. Builds the Editor and your Game. Disables optimizations on everything; your game, Engine, and Editor code.
  • DebugGame: Build your game without the Editor code, for packaged builds. Needs cooked assets. Disables optimizations on your game’s code, keeps Engine code optimized.
  • Debug: Build your game without the Editor code, for packaged builds. Needs cooked assets. Disables optimizations on both your game and Engine code.

If the Development configuration is optimizing your code too much to the point it makes debugging certain functions difficult then you’ll usually want to use DebugGame Editor for Editor builds, or DebugGame for packaged games if you want to be able to better debug your own code.

1 Like

Oh nice. I’ll give that a try. Thanks. :slight_smile:

This did indeed work, although the tags were off slightly. Here’s an example of the correct format. Note that the module names are case sensitive.

<?xml version="1.0" encoding="utf-8" ?>
<Configuration xmlns="https://www.unrealengine.com/BuildConfiguration">
<ModuleConfiguration>
  <DisableOptimizeCode>
  <Item>ModuleName</Item>
  <Item>ModuleName2</Item>
  <Item>ModuleName3</Item>
  </DisableOptimizeCode>
</ModuleConfiguration>
</Configuration>

Thanks for your help with this. It’s already been useful for me. :slight_smile:

2 Likes

Great you figured it out, thanks for posting your findings!

@dbrespawn Remember to mark this thread as resolved so future answer seekers know to check here if they’re having the same problems :slightly_smiling_face:

Ah, right. Done. :slight_smile:

1 Like