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

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

#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

MaterialFactoryNew requires the module UnrealEd which is an editor only module.

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

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

include “Factories/MaterialFactoryNew.h”

I know, hence the surrounding of a pragma like this

image

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

I should not get these errors

With the following commented out:

#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)

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?

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

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

example:


#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

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

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)

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

yet it STILL uses vs 2019

I guess I’ll have to uninstall it too

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

Another post on the forum touches on the subject

1 Like

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)