Error LNK2019 Trying to build the AssetRegistry demo

Gday All,
So I’m trying to use the Asset Registry example code, from here
Just to do a simple search to start off with but keep getting a LNK2019 error which I have been banging my head against for a couple of hours and can not see why :frowning:

my .h looks like this

#pragma once
#include "Engine.h"
#include "CoreMinimal.h"
#include "Runtime/Core/Public/Modules/ModuleManager.h"
#include "Runtime/AssetRegistry/Public/AssetRegistryModule.h"
#include "Runtime/AssetRegistry/Public/ARFilter.h"
#include "Engine/GameInstance.h"
#include "SRGameInstance.generated.h"

/**
 * 
 */
UCLASS()
class SAVAGEREALMS_API USRGameInstance : public UGameInstance
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintCallable, Category = "Component")
	TArray<FAssetData> GetClassFromString(FString className);
};

And my .cpp looks like this

#include "SRGameInstance.h"

TArray  USRGameInstance::GetClassFromString(FString className)
{
	FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
	TArray<FAssetData> AssetData;
	FARFilter Filter;
	Filter.PackagePaths.Add("/Game/Gameplay/Components/Items");
	AssetRegistryModule.Get().GetAssets(Filter, AssetData);
	return AssetData;
}

Any ideas on what I can do to fix this?

Awesome Master Gamgee, ummm I mean Samwise :slight_smile:

Worked a treat mate, just needed to add the AssetRegistry to the .build.cs and that was it, thank you so much, now I think I can figure out how to get the class reference I am after as it returned exactly what I need to do it, then I can close off my original question with an Answer :slight_smile:

SamWise to the rescue, his comment sorted me out :slight_smile:

Hey DavydM,

So a couple things that might work for you:

First, inside Visual Studio, find the “projectname”.build.cs file and add the module “AssetRegistry” like so:

Second, try changing your .cpp to look like mine here (it’s just line 7 from the snapshot):

Let me know if this helps at all!

2 Likes