# Resolving SetEnv error and unopenable source files while using Visual Studio in UE 5.7

**URL:** <https://forums.unrealengine.com/t/resolving-setenv-error-and-unopenable-source-files-while-using-visual-studio-in-ue-5-7/2682237>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, crash, question, CPP\
**Created:** [December 5, 2025, 5:54am UTC](https://forums.unrealengine.com/t/resolving-setenv-error-and-unopenable-source-files-while-using-visual-studio-in-ue-5-7/2682237 "2025-12-05T05:54:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seanny\_D](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Seanny\_D](https://forums.unrealengine.com/u/Seanny_D)\
**Post date:** [December 5, 2025, 5:54am UTC](https://forums.unrealengine.com/t/resolving-setenv-error-and-unopenable-source-files-while-using-visual-studio-in-ue-5-7/2682237/1 "2025-12-05T05:54:29Z")

</div>

I am new to Unreal Engine and have been trying to learn to use it with my existing knowledge of C++. I initially ran into issues with any blueprints I created that inherited from C++ classes losing their inheritance and becoming invalid after closing and opening the project, along with visual studio sometimes being completely unable to find either the object source files or the engine files.

I turned off live coding and am instead trying to build in visual studio directly. Whenever I try to build my project in visual studio however, I receive the following error: “MSB4018 The “SetEnv” task failed unexpectedly.”

I have been trying everything I can to solve this, including repairing visual studio and reinstalling UE 5, but so far nothing has worked. I feel like I must be missing something obvious because there is no way this is a normal thing.

Does anyone know what might be going on here? So far the C++ side of Unreal Engine has not worked since I downloaded it. I am happy to provide additional information.

---

<div class="post-metadata">

**Author:** ![BRGEzedeRocco](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/brgezederocco/32/1216890_2.png) [@BRGEzedeRocco](https://forums.unrealengine.com/u/BRGEzedeRocco)\
**Post date:** [December 5, 2025, 7:13pm UTC](https://forums.unrealengine.com/t/resolving-setenv-error-and-unopenable-source-files-while-using-visual-studio-in-ue-5-7/2682237/2 "2025-12-05T19:13:50Z")

</div>

Hi @Seanny_D ,Welcome to the forum!  
Great to see you jumping into the world of Unreal!

I did some searching and found a few posts where other users reported the same error you’re getting ( **MSB4018 SetEnv task failed unexpectedly** ), along with some potential solutions that worked for them.

> [@The "SetEnv" task failed unexpectedly](https://forums.unrealengine.com/t/the-setenv-task-failed-unexpectedly/2675115/10):
>
> I recently encountered the same error while building my project from Visual Studio: After some investigation, I noticed that the Unreal Engine Integration Configuration inside Visual Studio now exposes a setting called Max Include Paths Length (chars). This setting corresponds to the MaxSharedIncludePaths field inside BuildConfiguration.xml (located under UnrealBuildTool/BuildConfiguration, as shown in the screenshot blow). [IMG-20251118-3] Solution: I r…

> [@Unreal Engine 4.25 source code compile error](https://forums.unrealengine.com/t/unreal-engine-4-25-source-code-compile-error/141849/2):
>
> Solved. Simply deleted the paths to the inclusions, since there were strange paths in them.

I’m also sharing some official documentation that can help you get a better grasp of how to apply your C++ knowledge inside Unreal Engine.  
[https://dev.epicgames.com/documentation/en-us/unreal-engine/coding-in-unreal-engine-blueprint-vs-cplusplus?application\_version=5.5](https://dev.epicgames.com/documentation/en-us/unreal-engine/coding-in-unreal-engine-blueprint-vs-cplusplus?application_version=5.5)

> **[Programming with C++ in Unreal Engine | Unreal Engine 5.7 Documentation |...](https://dev.epicgames.com/documentation/en-us/unreal-engine/programming-with-cplusplus-in-unreal-engine)**
>
> Information for programmers developing with Unreal Engine.

There’s also a Learning site with tutorials that could help guide you as well.

> **[Epic Developer Community Learning | Tutorials, Courses, Demos & More –...](https://dev.epicgames.com/community/unreal-engine/learning)**
>
> Epic Developer Community Learning offers tutorials, courses, demos, and more created by Epic Games and the developer community.Learn UE and start creating today.

If you have any questions, don’t hesitate to ask here in the forum , there’s always someone willing to give you a hand with whatever you need!

Hope it helps and happy coding!

---

<div class="post-metadata">

**Author:** ![Seanny\_D](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Seanny\_D](https://forums.unrealengine.com/u/Seanny_D)\
**Post date:** [December 5, 2025, 11:53pm UTC](https://forums.unrealengine.com/t/resolving-setenv-error-and-unopenable-source-files-while-using-visual-studio-in-ue-5-7/2682237/4 "2025-12-05T23:53:14Z")

</div>

Okay thank you for finding this thread, after digging through it the solution that worked for me was going into the Unreal Engine Integration Configuration that opens when you start a UE project with C++, then setting Max Include Path under the Unreal Build Tool Configuration to something less than 32k (I did 20k), then clicking regenerate the current solution and apply Unreal Build Tool Config, closing VS, opening the project back up and rebuilding, then going in and using the unreal engine editor.

I think the error may have initially popped up again when I rebuilt it… but since then I have built the project multiple times in VS after making changes to test if it was working and all the builds have succeeded without error.

Also I greatly appreciate the extra C++ resources.

---

<div class="post-metadata">

**Author:** ![Aqibbhai](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aqibbhai](https://forums.unrealengine.com/u/Aqibbhai)\
**Post date:** [February 3, 2026, 10:00pm UTC](https://forums.unrealengine.com/t/resolving-setenv-error-and-unopenable-source-files-while-using-visual-studio-in-ue-5-7/2682237/5 "2026-02-03T22:00:56Z")

</div>

Can someone teach me how to do it I am facing the exact same thing as well

---

<div class="post-metadata">

**Author:** ![wms970](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@wms970](https://forums.unrealengine.com/u/wms970)\
**Post date:** [February 23, 2026, 3:49pm UTC](https://forums.unrealengine.com/t/resolving-setenv-error-and-unopenable-source-files-while-using-visual-studio-in-ue-5-7/2682237/6 "2026-02-23T15:49:21Z")

</div>

**Root Cause:** The `BuildConfiguration.xml` file contained a `MaxSharedIncludePaths` entry with a large value, which caused the environment variable to exceed Windows’ length limit, triggering the MSBuild `SetEnv` error.

**Solution:**

1. Navigate to `C:\Users\[YourName]\AppData\Roaming\Unreal Engine\UnrealBuildTool\BuildConfiguration.xml`

2. Remove the `MaxSharedIncludePaths` line so the file looks like this:

xml

```auto
<?xml version="1.0" encoding="utf-8" ?>
<Configuration xmlns="https://www.unrealengine.com/BuildConfiguration">
</Configuration>

```

1. Delete the existing `.sln` file

2. Right-click your `.uproject` → **Generate Visual Studio project files**

3. Build again in Visual Studio

---

<div class="post-metadata">

**Author:** ![frankiemhm](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@frankiemhm](https://forums.unrealengine.com/u/frankiemhm)\
**Post date:** [August 17, 2026, 5:56pm UTC](https://forums.unrealengine.com/t/resolving-setenv-error-and-unopenable-source-files-while-using-visual-studio-in-ue-5-7/2682237/7 "2026-08-17T17:56:37Z")

</div>

Ur a legend 4 this.

Idk why ts can’t just be straightforward for some of us 🫠 Like welcome to Unreal Engine! Everything can’t build because of an error that’s integrated within our systems!
