# Project cannot compile during packaging - No such file or directory - but can run game and build from VS2022

**URL:** <https://forums.unrealengine.com/t/project-cannot-compile-during-packaging-no-such-file-or-directory-but-can-run-game-and-build-from-vs2022/1136290>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [April 21, 2023, 10:49pm UTC](https://forums.unrealengine.com/t/project-cannot-compile-during-packaging-no-such-file-or-directory-but-can-run-game-and-build-from-vs2022/1136290 "2023-04-21T22:49:09Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![phil123456](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@phil123456](https://forums.unrealengine.com/u/phil123456)\
**Post date:** [April 21, 2023, 10:49pm UTC](https://forums.unrealengine.com/t/project-cannot-compile-during-packaging-no-such-file-or-directory-but-can-run-game-and-build-from-vs2022/1136290/1 "2023-04-21T22:49:09Z")

</div>

Hi,

I cannot package my game

`Cannot open include file: 'Factories/MaterialFactoryNew.h': No such file or directory`

but I can run the editor from VS2022 without an issue

this is a simple class generated from the editor, that has AActor as a parent class

```auto
#pragma once

#include <string>
#include <Kismet/GameplayStatics.h>
#include <GameFramework/GameModeBase.h>
#include <Factories/MaterialFactoryNew.h>
#include <PackageTools.h>

#include "AssetRegistry/AssetRegistryModule.h"
#include "Materials/MaterialExpressionMultiply.h"
#include "Materials/MaterialExpressionAppendVector.h"
#include "Materials/MaterialExpressionTextureCoordinate.h"
#include "Materials/MaterialExpressionScalarParameter.h"
#include "Components/PointLightComponent.h"
#include "Engine/LevelScriptActor.h"
#include "Components/CapsuleComponent.h"
#include "Engine/World.h"
#include "CoreMinimal.h"

#include "MyCppActor.h"
#include "MyBlueprintFunctionLibrary.h"
#include "BlenderCsvData.h"
#include "WheeledVehicle.h"

#include "MyCppWheeledVehicle.generated.h"

/**
 * 
 */
UCLASS()
class ROBOTMONK_4_27_API AMyCppWheeledVehicle : public AActor //AWheeledVehicle
{
	GENERATED_BODY()

public:
	AMyCppWheeledVehicle();
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Meshes)
	TArray<USceneComponent*> ChildSceneComponents;
	//void OnConstruction(const FTransform& Transform) override;

private:
#ifdef WITH_EDITOR
	void ImportFromBlender();
	UDataTable* AMyCppWheeledVehicle::CsvToTable(FString path);
	TArray<FString> GetCSVFile(FString Path);
	UStaticMeshComponent* AddStaticMesh(FString name, FString path, FVector location, FRotator rotation, FVector scale);
	UTexture* LoadTexture(FString RootPath, FString path);
	UPointLightComponent* CreateLight(FString name, FVector Location, float DesiredIntensity);
	UMaterial* CreateMaterial(FString MeshName, FString RootPath, FString DiffuseTexturePath, FString AlphaTexturePath, FString EmissiveTexturePath);
#endif
};

```

what am I missing ?

thanks for your help

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [April 22, 2023, 9:21am UTC](https://forums.unrealengine.com/t/project-cannot-compile-during-packaging-no-such-file-or-directory-but-can-run-game-and-build-from-vs2022/1136290/2 "2023-04-22T09:21:34Z")

</div>

MaterialFactoryNew requires the module [UnrealEd](https://docs.unrealengine.com/5.1/en-US/API/Editor/UnrealEd/) which is an editor only module.

This thread might be of help regarding getting UnrealEd in a packaged project up and running

> [@UnrealEd Dependency Causes Package Failure](https://forums.unrealengine.com/t/unrealed-dependency-causes-package-failure/19940/3):
>
> Michael, thank you very much for the quick response! I’ve setup a new module that encapsulates my editor code and I am able to get it to compile. However when I package I still run into the same issue, I thought the ‘Type’:‘Editor’ would take care of the ‘don’t include it when cooking’ part of your suggestion but I’m guessing that is not enough. Might anyone know how can I make it so that my new editor module is not included when I package the game?

Also try replacing the angled brackets with double quotation marks as in the unreal documentation

#include “Factories/MaterialFactoryNew.h”

---

<div class="post-metadata">

**Author:** ![phil123456](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@phil123456](https://forums.unrealengine.com/u/phil123456)\
**Post date:** [April 22, 2023, 11:51am UTC](https://forums.unrealengine.com/t/project-cannot-compile-during-packaging-no-such-file-or-directory-but-can-run-game-and-build-from-vs2022/1136290/3 "2023-04-22T11:51:45Z")

</div>

I know, hence the surrounding of a pragma like this

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/f/d/afd4cb14a73928559b0ce04c7c15d0485fbd50b1.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/a/e/eae24a62ae0ce3867a77e0996f84d464ffcf7deb.png)

```auto
#if WITH_EDITORONLY_DATA
	dynamicCanvas->MipGenSettings = TextureMipGenSettings::TMGS_NoMipmaps;
#endif

```

I should not get these errors

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [April 22, 2023, 12:54pm UTC](https://forums.unrealengine.com/t/project-cannot-compile-during-packaging-no-such-file-or-directory-but-can-run-game-and-build-from-vs2022/1136290/4 "2023-04-22T12:54:14Z")

</div>

With the following commented out:

```auto
#include "MyCppActor.h"
#include "MyBlueprintFunctionLibrary.h"
#include "BlenderCsvData.h"
#include "WheeledVehicle.h"

```

and adding #include “Engine/DataTable.h” it compiles just fine and runs the editor (4.27)

 ![compiles](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/4/b/d4bbd994ec7c55a54751f4ee961bf7c6d0352180.png)

Could there be a conflict with something within the commented includes?

Edit:  
Perhaps move the load functions to their own static library to make them more reusable?

---

<div class="post-metadata">

**Author:** ![phil123456](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@phil123456](https://forums.unrealengine.com/u/phil123456)\
**Post date:** [April 22, 2023, 7:16pm UTC](https://forums.unrealengine.com/t/project-cannot-compile-during-packaging-no-such-file-or-directory-but-can-run-game-and-build-from-vs2022/1136290/5 "2023-04-22T19:16:11Z")

</div>

can you package it ?  
I can compile, I just cannot package it

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [April 22, 2023, 7:27pm UTC](https://forums.unrealengine.com/t/project-cannot-compile-during-packaging-no-such-file-or-directory-but-can-run-game-and-build-from-vs2022/1136290/6 "2023-04-22T19:27:00Z")

</div>

Yes but i need to add an if statement to cut out editor tool includes

example:

```auto

#include <string>
#include "Kismet/GameplayStatics.h"
#include "GameFramework/GameModeBase.h"
#if UE_EDITOR
#include "Factories/MaterialFactoryNew.h"
#include "PackageTools.h"
#endif

```

edit:  
#if WITH\_EDITOR works too

---

<div class="post-metadata">

**Author:** ![phil123456](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@phil123456](https://forums.unrealengine.com/u/phil123456)\
**Post date:** [April 22, 2023, 7:48pm UTC](https://forums.unrealengine.com/t/project-cannot-compile-during-packaging-no-such-file-or-directory-but-can-run-game-and-build-from-vs2022/1136290/7 "2023-04-22T19:48:19Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/3/b/73b4f54d95eaef1ae0e734b07dcb460c9694d51b.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/3/5/135d75fd829990ef21d17bb1f11585c94140df18.png)

also I noticed , as I use VS2022, the editor launches VS2019  
where do I change that ?

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [April 22, 2023, 7:50pm UTC](https://forums.unrealengine.com/t/project-cannot-compile-during-packaging-no-such-file-or-directory-but-can-run-game-and-build-from-vs2022/1136290/8 "2023-04-22T19:50:54Z")

</div>

ifdef doesn’t work on headers due to it being ignored in pre-compile stages. Use just #if WITH\_EDITOR

I uninstalled vs 2019 to stop it launching.

edit:  
Just include the includes that are editor only in the if statement (the 2 I mentioned are enough to get a packaged project finish with no errors)

---

<div class="post-metadata">

**Author:** ![phil123456](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@phil123456](https://forums.unrealengine.com/u/phil123456)\
**Post date:** [April 22, 2023, 7:58pm UTC](https://forums.unrealengine.com/t/project-cannot-compile-during-packaging-no-such-file-or-directory-but-can-run-game-and-build-from-vs2022/1136290/9 "2023-04-22T19:58:54Z")

</div>

did you check my screen shot ?  
I literally put everything in between #ifdef WITH\_EDITOR …#endif

I also found where to set the toolchain for the packaging

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/e/2/ae2e51a368a63ac9dc7e5d57d71a809dcdda4526.png)

yet it STILL uses vs 2019

I guess I’ll have to uninstall it too

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [April 22, 2023, 7:59pm UTC](https://forums.unrealengine.com/t/project-cannot-compile-during-packaging-no-such-file-or-directory-but-can-run-game-and-build-from-vs2022/1136290/10 "2023-04-22T19:59:43Z")

</div>

Like I mentioned #Ifdef does not work on header includes … use #if

Another post on the forum touches on the subject

> [@Using #ifdef doesn't work with Unreal Header Tool](https://forums.unrealengine.com/t/using-ifdef-doesnt-work-with-unreal-header-tool/366377/4):
>
> You don’t need the defined keyword. If it is not defined it is falsy. You are doing the equivalent of this in the macro world: if (I \< 5 || 10 || 17) This is an illegal statement. The code you want is: #if \_\_cplusplus || UE\_GAME || UE\_EDITOR || UE\_SERVER

---

<div class="post-metadata">

**Author:** ![phil123456](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@phil123456](https://forums.unrealengine.com/u/phil123456)\
**Post date:** [April 22, 2023, 8:07pm UTC](https://forums.unrealengine.com/t/project-cannot-compile-during-packaging-no-such-file-or-directory-but-can-run-game-and-build-from-vs2022/1136290/11 "2023-04-22T20:07:20Z")

</div>

arf god ■■■■ f@#king C++

also even if I run the editor from VS2022, it uses VS2019 for a toolchain

I’ll try this one [Packaging Plugin Calls Wrong Version of Visual Studio - Pipeline & Plugins / Plugins - Epic Developer Community Forums (unrealengine.com)](https://forums.unrealengine.com/t/packaging-plugin-calls-wrong-version-of-visual-studio/483625)
