# How to enable AVX or SSE optimizations while building UE4 project?

**URL:** <https://forums.unrealengine.com/t/how-to-enable-avx-or-sse-optimizations-while-building-ue4-project/344247>\
**Category:** Debugging, Optimization, & Profiling\
**Tags:** c-build, Optimization, compiling, unreal-engine, unrealbuildtool, building, question\
**Created:** [January 16, 2016, 2:10am UTC](https://forums.unrealengine.com/t/how-to-enable-avx-or-sse-optimizations-while-building-ue4-project/344247 "2016-01-16T02:10:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_19fd3ec21](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_19fd3ec21](https://forums.unrealengine.com/u/anonymous_user_19fd3ec21)\
**Post date:** [January 16, 2016, 2:10am UTC](https://forums.unrealengine.com/t/how-to-enable-avx-or-sse-optimizations-while-building-ue4-project/344247/1 "2016-01-16T02:10:32Z")

</div>

I have a library which uses AVX and SSE optimizations, to enable these it expects " /arch:AVX " flag to be passed to Visual C++ compiler.  
I do not see any option to set compiler flags in UE4 project. Is there any way to do this?

Thanks

---

<div class="post-metadata">

**Author:** ![Pierdek](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pierdek](https://forums.unrealengine.com/u/Pierdek)\
**Post date:** [January 17, 2016, 12:03am UTC](https://forums.unrealengine.com/t/how-to-enable-avx-or-sse-optimizations-while-building-ue4-project/344247/2 "2016-01-17T00:03:32Z")

</div>

Engine\Source\Programs\UnrealBuildTool\Windows\VCToolChain.cs

```
//
			//	PC
			//
			if ((CompileEnvironment.Config.Target.Platform == CPPTargetPlatform.Win32) || 
				(CompileEnvironment.Config.Target.Platform == CPPTargetPlatform.Win64))
			{
				// SSE options are not allowed when using CLR compilation
				if (CompileEnvironment.Config.CLRMode == CPPCLRMode.CLRDisabled && WindowsPlatform.bUseVCCompilerArgs)
				{
					if (CompileEnvironment.Config.bUseAVX)
					{
						// Allow the compiler to generate AVX instructions.
						Arguments.Append(" /arch:AVX");
					}
					// SSE options are not allowed when using the 64 bit toolchain
					// (enables SSE2 automatically)
					else if (CompileEnvironment.Config.Target.Platform != CPPTargetPlatform.Win64)
					{
						// Allow the compiler to generate SSE2 instructions.
						Arguments.Append(" /arch:SSE2");
					}
				}

```

As you see, you have to provide somehow bUseAVX flag, I believe this may be done in:

```
public override void SetupGlobalEnvironment(
        TargetInfo Target,
        ref LinkEnvironmentConfiguration OutLinkEnvironmentConfiguration,
        ref CPPEnvironmentConfiguration OutCPPEnvironmentConfiguration
        )
    {
    }

```

in your project TargetRules. For example take a look at Engine\Source\UE4Game.Target.cs

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_19fd3ec21](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_19fd3ec21](https://forums.unrealengine.com/u/anonymous_user_19fd3ec21)\
**Post date:** [January 25, 2016, 7:04pm UTC](https://forums.unrealengine.com/t/how-to-enable-avx-or-sse-optimizations-while-building-ue4-project/344247/3 "2016-01-25T19:04:48Z")

</div>

Hi ,  
Sorry for the late reply.

Is there a way to do this without modifying / compiling the engine from source ?

The tried override of _SetupGlobalEnvironment_ in _MyGame.Target.cs_ and _MyGameEditor.Target.cs_, but it was not called.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_589bfbc4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_589bfbc4](https://forums.unrealengine.com/u/anonymous_user_589bfbc4)\
**Post date:** [August 5, 2016, 9:52pm UTC](https://forums.unrealengine.com/t/how-to-enable-avx-or-sse-optimizations-while-building-ue4-project/344247/4 "2016-08-05T21:52:59Z")

</div>

Use in your project TargetRules.

```
 public override void SetupGlobalEnvironment(
         TargetInfo Target,
         ref LinkEnvironmentConfiguration OutLinkEnvironmentConfiguration,
         ref CPPEnvironmentConfiguration OutCPPEnvironmentConfiguration
         )
     {
OutCPPEnvironmentConfiguration.bUseAVX = true;
     }

```
