Hey all, i’m having a really weird issue with generating the VS Code Project Files for my project.
I recently had to reformat my hard drive, but a friend and I have been storing our project in perforce.
On loading the project up I get this error which is new
Failed to import 'd:/Program Files/Epic Games/UE_5.2/FeaturePacks/StarterContent.upack'. Failed to create asset '/Game/StarterContent'.
Please see Output Log for details.
I’ve gone through, reinstalled the engine version (5.2) and reinstalled all of the dependencies, and set up it up to use VS Code, however when I try and generate the files I get this error.
Note that the person i’m working with isn’t getting this error, and if I generate other projects on the same version I’m able to launch VS code and compile without any problems. It seems just related to this specific project and I have no idea why.
An error occurred while trying to generate project files.
Running d:/Program Files/Epic Games/UE_5.2/Engine/Build/BatchFiles/Build.bat -projectfiles -project="C:/UnrealDev/Perforce/LatentSpace/GameJameLatentSpace.uproject" -game -rocket -progress
Using bundled DotNet SDK version: 6.0.302
Running UnrealBuildTool: dotnet "..\..\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.dll" -projectfiles -project="C:/UnrealDev/Perforce/LatentSpace/GameJameLatentSpace.uproject" -game -rocket -progress
Log file: C:\Users\Reede.REEDE\AppData\Local\UnrealBuildTool\Log_GPF.txt
Some Platforms were skipped due to invalid SDK setup: IOS, Android, Linux, LinuxArm64.
See the log file for detailed information
Generating VisualStudioCode project files:
Discovering modules, targets and source code for project...
Binding IntelliSense data...
Binding IntelliSense data... 100%
Writing project files...
Writing project files... 50%
Unhandled exception: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
at UnrealBuildTool.VSCodeProjectFileGenerator.WriteWorkspaceIgnoreFile(List`1 Projects) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\VisualStudioCode\VSCodeProjectFileGenerator.cs:line 1554
at UnrealBuildTool.VSCodeProjectFileGenerator.WritePrimaryProjectFile(ProjectFile UBTProject, PlatformProjectGeneratorCollection PlatformProjectGenerators, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\VisualStudioCode\VSCodeProjectFileGenerator.cs:line 288
at UnrealBuildTool.ProjectFileGenerator.WriteProjectFiles(PlatformProjectGeneratorCollection PlatformProjectGenerators, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\ProjectFileGenerator.cs:line 2852
at UnrealBuildTool.ProjectFileGenerator.GenerateProjectFiles(PlatformProjectGeneratorCollection PlatformProjectGenerators, String[] Arguments, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\ProjectFileGenerator.cs:line 1194
at UnrealBuildTool.GenerateProjectFilesMode.Execute(CommandLineArguments Arguments, ILogger Logger) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\Modes\GenerateProjectFilesMode.cs:line 67
at UnrealBuildTool.UnrealBuildTool.Main(String[] ArgumentsArray) in D:\build\++UE5\Sync\Engine\Saved\CsTools\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.cs:line 599
Per your provided log and background, the issue is most likely isolated to that particular project, indeed. A similar scenario was encountered in the thread below, and the solution was to migrate the contents to a new project:
Alternatively, you can try clearing the project’s cache, via deleting the following folders from your directory:
Binaries/
Intermediate/
Saved/
.vs/
As per the potential problem with StarterContent, you can force the file’s re-creation. Simply delete StarterContent.upac from the FeaturePacks directory. After that, right click your install in the launcher, and choose Verify, which will force a fresh download.
So, for the starter content, I did go through, delete the original and then verify and had it reinstall. Unfortunatley opening the project I still get this error. I even went so far as to totally remove 5.2 and reinstall it, same thing.
And then I did remove all of the non-essential folders in the project, binaries, intermediate, saved, .vscode and tried generating the vs files again and i keep getting the same index was out of range error.
The part that is leaving me at a loss is while I can definitely see its related to the project, the other person working with me and building from the same source is not getting the error, which leads to me to think it has to be a local dependency issues, but I have no idea where to start looking for what would be the cause.
So it is starting to look like it’s something related to Visual Studio Code. Switched it over to Visual Studios 2022 and those genereated without any issue and i’m able to build, but switching it back to VSCode I then run into the issue generating the files again.
I did install the C/C++ extension and C# packs per the documentation, so I have the others installed from it, but wondering if i’m missing something? It’s pretty sparse as I did just recently reformat my computer, this going through all of this trying to get my env set back up.
Alright, it took me a bit and the other person I’m working on the project with apparently had this issue as well a while ago.
Looks like there’s essentially a bug in the 5.2 engine VSCodeProjectFileGenerator.cs
in my case installed at C:\Program Files\Epic Games\UE_5.2\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\VisualStudioCode\VSCodeProjectFileGenerator.cs
Down around line 1554 it checks a reference to Projects[0].BaseDir which i’m assuming has no entires, thus the index out of range error as this is the first 5.2 project i’m setting up on this computer. So at least a quick fix that seems to be working is returning if Projects is null or 0
// Line 1552 Code I added to fix the issue
if (Projects == null || Projects.Count == 0) {
return;
}
With this the generator runs succesfully with no errors, though do note I had to open the UnrealBuildTool.sln and rebuild it before it took effect (rebuilt by just opening it with Visual Studios 2022 and selecting build, upon success i could then just right click on the .uproject file for my project and running “generate visual studios project files” C:\Program Files\Epic Games\UE_5.2\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.sln
So this all happened because I had to reformat my computer, but originally I had a few other 5.2 projects from some tutorials I had worked through that just used blueprints, so no coding or opening in VS Code before. I’m guessing because they existed the Projects var had multiple other entries resulting in me not having a problem when I originally set this new project up.
So in theory if you don’t want to mess with engine code you could potentially make multiple 5.2 projects before the one you want to actually build?
Side note to the StaterContent.upack issue, so if I just delete it out of the 5.2 engine directory and load up the project there’s no error, but revalidating and getting the file back in will show the error again, so at least for now planning to just delete it and hopefully it won’t cause any issues