How to access Object Tools in C++?

Hi guys,

I wrote the following code:

CreviceFunctionLibrary.h:

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "CreviceDataSingleton.h"
#include "CreviceFunctionLibrary.generated.h"

/**
 * 
 */
UCLASS()
class CREVICERPG_API UCreviceFunctionLibrary : public UObject
{
	GENERATED_BODY()

	UFUNCTION(BlueprintPure, Category = "Utility")
	static void ConsolidateAssets(UObject* AssetToConsolidateTo, TArray<UObject*> &AssetsToReplace, bool bShowDeleteConfirmation = true);
};

CreviceFunctionLibrary.cpp

#include "CreviceRPG.h"
#include "ObjectTools.h"
#include "CreviceFunctionLibrary.h"

void UCreviceFunctionLibrary::ConsolidateAssets(UObject* AssetToConsolidateTo, TArray<UObject*> &AssetsToReplace, bool bShowDeleteConfirmation)
{
	ObjectTools::FConsolidationResults ConsResults = ObjectTools::ConsolidateObjects(AssetToConsolidateTo, AssetsToReplace, bShowDeleteConfirmation);
}

I’m getting the following errors:

2>CreviceFunctionLibrary.cpp.obj : error LNK2019: Verweis auf nicht aufgel÷stes externes Symbol ""__declspec(dllimport) public: virtual __cdecl ObjectTools::FConsolidationResults::~FConsolidationResults(void)" (__imp_??1FConsolidationResults@ObjectTools@@UEAA@XZ)" in Funktion ""private: static void __cdecl UCreviceFunctionLibrary::ConsolidateAssets(class UObject *,class TArray<class UObject *,class FDefaultAllocator> &,bool)" (?ConsolidateAssets@UCreviceFunctionLibrary@@CAXPEAVUObject@@AEAV?$TArray@PEAVUObject@@VFDefaultAllocator@@@@_N@Z)".
2>CreviceFunctionLibrary.cpp.obj : error LNK2019: Verweis auf nicht aufgel÷stes externes Symbol ""__declspec(dllimport) struct ObjectTools::FConsolidationResults __cdecl ObjectTools::ConsolidateObjects(class UObject *,class TArray<class UObject *,class FDefaultAllocator> &,bool)" (__imp_?ConsolidateObjects@ObjectTools@@YA?AUFConsolidationResults@1@PEAVUObject@@AEAV?$TArray@PEAVUObject@@VFDefaultAllocator@@@@_N@Z)" in Funktion ""private: static void __cdecl UCreviceFunctionLibrary::ConsolidateAssets(class UObject *,class TArray<class UObject *,class FDefaultAllocator> &,bool)" (?ConsolidateAssets@UCreviceFunctionLibrary@@CAXPEAVUObject@@AEAV?$TArray@PEAVUObject@@VFDefaultAllocator@@@@_N@Z)".

There seems to be a problem to accessing the ObjectTools namespace, and I didn’t manage to find out what caused this error. Does anyone know about that?

Cheers,

Luke

That solved it! Thank you a lot! :slight_smile:

Hi!Did you add the module “UnrealEd” to the build.cs file and regenerate the project? Cause UE4 doesnt know where to find this headers by default.

its under the “UnrealEd” module.

Keep in mind that id you add dependency to UnrealEd, you codem odule effectively becomes editor module and it will throw oyu errors on packageing to any non-editor build. You need to edit either uproject or uplugin and change Type of module you making from Runtime to Editor. You probably will need to make seperate runtime module for code that will run at runtime.

You can also make conditional dependency in build.cs so it only depend on it when you module is build for editor use and filter the editor dependent code with #if WITH_EDITOR , this let oyu have osme editor only code in runtime module without any packaging issues

Thank you, I’ll try the WITH_EDITOR solution. :slight_smile: