Enviroment variable too long

I am compiling a c++ project with visual studio 2022 and I am getting an error (System.ArgumentException in System.Environment.SetEnvironmentVariable(String variable, String value)
in System.Environment.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)
in Microsoft.Build.CPPTasks.SetEnv.Execute()
in Microsoft.Build.BackEnd.TaskExecutionHost.Execute()) that say an EnviromentVariable name or value is long.
Before I started getting this error, I messed up with visual studio updating it to 2026 version and I installed the UE5 5.7.1 version. Now I am back to the Visual studio 2022 version but I have again the error (I regenerated Visual Studio files by the project file).

How can I fix this error?

Hey there @Reicon! The EnvironmentVariable name or value is long makes me believe that maybe an environment variable call to a core engine function has too long of a directory, but that shouldn’t have changed with your VS upgrade, so I’d be more inclined to believe something with the build tool changed.

I found a thread on VS forums side that corroborates my theory that it’s possible Unreal Build Tool is at fault.


First, I’ll recommend backing up your project and any data that we would be removing and regenerating here, just in case.

Next let’s delete and regenerate the Saved, Intermediate, and DerivedDataCache folders in the project.

Then find your UBT configuration in the engine’s files, roughly around here: C:\Users\{YOURUSERNAME}\AppData\Roaming\Unreal Engine\UnrealBuildTool\ called BuildConfiguration.xml, delete that, then regenerate your project’s VS solution.

Then when you launch the engine and the project, the rest of the removed folders should regenerate as well. Does this change anything?