4.20 DirectX compilation error

When building a project I get this error: " Unable to expand variable in ‘$(DXSDK_DIR)\Lib\x64’ ".

I also use Wwise plugin and I’ve found the exast same string as an input to PublicIncludePaths in the build.cs of Wwise. However, this error never appeared in the previous versions with that same string as an included public path.

Does this happen because of some changes in 4.20? Do I have to update DirectX?

I’m also having that problem, it’s caused by WWise. I’m taking a look at it and i’ll let you know if i find anything useful. Right now all i have is the log information:

UEBuildTarget.AddPlugin: Enabling plugin 'Wwise' (referenced via default plugins)
<>c.<PrintExceptionInfo>b__4_1: ==============================================================================
<>c.<PrintExceptionInfo>b__4_0: UnrealBuildTool: ERROR: Unable to expand variable in '$(DXSDK_DIR)\Lib\x64'
<>c.<PrintExceptionInfo>b__4_0:                         (see ../Programs/UnrealBuildTool/Log.txt for full exception trace)
<>c.<PrintExceptionInfo>b__4_1: 
<>c.<PrintExceptionInfo>b__4_1: BuildException: Unable to expand variable in '$(DXSDK_DIR)\Lib\x64'
<>c.<PrintExceptionInfo>b__4_1:    at UnrealBuildTool.UEBuildModule.CreateDirectoryHashSet(IEnumerable`1 InEnumerableStrings) in D:\Build\++UE4\Sync\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Configuration\UEBuildModule.cs:line 259
<>c.<PrintExceptionInfo>b__4_1:    at UnrealBuildTool.UEBuildModule..ctor(String InName, UHTModuleType InType, DirectoryReference InModuleDirectory, ModuleRules InRules, FileReference InRulesFile, List`1 InRuntimeDependencies) in D:\Build\++UE4\Sync\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Configuration\UEBuildModule.cs:line 182
<>c.<PrintExceptionInfo>b__4_1:    at UnrealBuildTool.UEBuildModuleCPP..ctor(String InName, UHTModuleType InType, DirectoryReference InModuleDirectory, DirectoryReference InIntermediateDirectory, DirectoryReference InGeneratedCodeDirectory, IEnumerable`1 InSourceFiles, ModuleRules InRules, Boolean bInBuildSourceFiles, FileReference InRulesFile, List`1 InRuntimeDependencies) in D:\Build\++UE4\Sync\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Configuration\UEBuildModuleCPP.cs:line 286
<>c.<PrintExceptionInfo>b__4_1:    at UnrealBuildTool.UEBuildTarget.InstantiateModule(ModuleRules RulesObject, String ModuleName, UHTModuleType ModuleType, DirectoryReference ModuleDirectory, DirectoryReference GeneratedCodeDirectory, List`1 ModuleSourceFiles, Boolean bBuildSourceFiles, FileReference InRulesFile, List`1 InRuntimeDependencies, PluginInfo Plugin) in D:\Build\++UE4\Sync\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Configuration\UEBuildTarget.cs:line 4378
<>c.<PrintExceptionInfo>b__4_1:    at UnrealBuildTool.UEBuildTarget.FindOrCreateModuleByName(String ModuleName, String ReferenceChain) in D:\Build\++UE4\Sync\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Configuration\UEBuildTarget.cs:line 4340
<>c.<PrintExceptionInfo>b__4_1:    at UnrealBuildTool.UEBuildTarget.FindOrCreateCppModuleByName(String ModuleName, String ReferenceChain) in D:\Build\++UE4\Sync\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Configuration\UEBuildTarget.cs:line 4355
<>c.<PrintExceptionInfo>b__4_1:    at UnrealBuildTool.UEBuildTarget.AddPlugin(PluginReferenceDescriptor Reference, String ReferenceChain, FileSystemName[] ExcludeFolders, Dictionary`2 NameToInstance, Dictionary`2 NameToInfo) in D:\Build\++UE4\Sync\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Configuration\UEBuildTarget.cs:line 3582
<>c.<PrintExceptionInfo>b__4_1:    at UnrealBuildTool.UEBuildTarget.SetupPlugins() in D:\Build\++UE4\Sync\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Configuration\UEBuildTarget.cs:line 3439
<>c.<PrintExceptionInfo>b__4_1:    at UnrealBuildTool.UEBuildTarget.PreBuildSetup(UEToolChain TargetToolChain) in D:\Build\++UE4\Sync\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Configuration\UEBuildTarget.cs:line 2622
<>c.<PrintExceptionInfo>b__4_1:    at UnrealBuildTool.UEBuildTarget.Build(BuildConfiguration BuildConfiguration, CPPHeaders Headers, List`1 OutputItems, List`1 UObjectModules, ISourceFileWorkingSet WorkingSet, ActionGraph ActionGraph, EHotReload HotReload, Boolean bIsAssemblingBuild) in D:\Build\++UE4\Sync\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Configuration\UEBuildTarget.cs:line 2021
<>c.<PrintExceptionInfo>b__4_1:    at UnrealBuildTool.UnrealBuildTool.RunUBT(BuildConfiguration BuildConfiguration, String[] Arguments, FileReference ProjectFile, Boolean bCatchExceptions) in D:\Build\++UE4\Sync\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.cs:line 1480
<>c.<PrintExceptionInfo>b__4_1: ==============================================================================

Update 1:

The problem is in the AkAudio.Build.cs for WWise Plugin:

PublicLibraryPaths.Add("$(DXSDK_DIR)" + Path.DirectorySeparatorChar + “Lib” + Path.DirectorySeparatorChar + LibFolder);

My guess is that we are missing the DXSDK_DIR environment variable in Windows to set the path to the directx sdk folder. So i need to find where it is.

Yes, as I mentioned I’ve found that line as well but there is the same line in the previous versions of Wwise so I suppose this has to be connected with the switch to VS 2017 as it cannot find the directory of DirectX

The UE 4 installation seems to have the files (C:\Program Files\Epic Games\UE_4.20\Engine\Source\ThirdParty\Windows\DirectX) but creating the environment variable with that value still produces the same error. If you use the directory with forward slashes directly in the code instead of $(DXSDK_DIR) then it works as a temporary workaround.

As an alternative you can use:

string DXSDK_DIR = Environment.GetEnvironmentVariable("DXSDK_DIR", EnvironmentVariableTarget.Machine); // use EnvironmentVariableTarget.User if you added it on the user side instead of the system side.

PublicLibraryPaths.Add(DXSDK_DIR + Path.DirectorySeparatorChar + "Lib" + Path.DirectorySeparatorChar + LibFolder);

As a better alternative (that doesn’t use environment variables at all) you can use:

string DXSDK_DIR = Path.GetFullPath(Path.Combine(EngineDirectory, "Source/ThirdParty/Windows/DirectX"));

Thanks, I’ll give it a try

Make sure you have “AkAudio” on the PublicDependencyModuleNames for your Build.cs. If it’s not finding it anyway, make sure you have the proper includes to use that type.

When I do that I instead get a new error (AkAcousticPortal.h(38): error : Unrecognized type ‘AkAcousticPortalState’ - type must be a UCLASS, USTRUCT or UENUM)

Thanks for helping out. By build.cs I suppose you are talking about the game/project Build.cs? I have tryed to include it there with no success.
I haven’t done any edits in the Wwise module other than what you proposed with the string DXSDK_DIR so I wonder why the module suddenly fails to compile. I have the Wwise module installed as a project module but I am now trying to install it as an engine plugin instead to see if that helps.

I also don’t use any Wwise functions in my project code but have had it included anyway with no issues in 4.19. I am searching for problems created by the upgrade and changes made in 4.20.

Installing Wwise as an engine plugin (as opposed to project plugin) and applying your DX path solution seems to have solved the compile problem. Thanks again for the help.

Yes add that to the game’s Build.cs. At least i’m not having any compilation issues although i haven’t used anything from WWise in my code yet.

Sorry for the delay. I tried this and it worked, thank you

I apologize, but I have run into the same error and can’t seem to apply the fix correctly. Is it possible to get a summarized answer of the correct solution? I am unsure as to which of your suggested fixed ended up being used and where. Thank you!!

For what problem exactly? The “Unable to expand variable in ‘$(DXSDK_DIR)\Lib\x64’”?

That is correct.

Go to AkAudio.Build.cs and find where it says:

PublicLibraryPaths.Add("$(DXSDK_DIR)" + Path.DirectorySeparatorChar + "Lib" + Path.DirectorySeparatorChar + LibFolder);

and replace that with:

string DXSDK_DIR = Path.GetFullPath(Path.Combine(EngineDirectory, "Source/ThirdParty/Windows/DirectX"));
PublicLibraryPaths.Add(DXSDK_DIR + Path.DirectorySeparatorChar + "Lib" + Path.DirectorySeparatorChar + LibFolder);

I was having the same issue as OP and the above information helped fix it. Now I’m getting a different error that is also related to Wwise.

c.<PrintExceptionInfo>b__4_0: ERROR: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Program Files\Epic Games\UE_4.20\Engine\Plugins\Wwise\Intermediate\Build\Win32\UE4\Development\AkAudio\AkAudio.precompiled'.

I checked the directory and it only goes up to Wwise and has no intermediate. any Idea what I need to do to fix this?

I have installed the WWise plugin only in my game and not on the engine, so maybe you can try to regenerate the visual studio solution of the game and try to recompile.