Conversion error in FObjectFinder

I’m working on an inventory system and using FObjectFinder to find the Item database in my editor.
Here is my code:

#include "MeatGameState.h"
#include "UObject/ConstructorHelpers.h"

AMeatGameState::AMeatGameState()
{
	const FString BP_ITEMDB = "DataTable'/Game/Data/ItemDB.ItemDB'";
	static ConstructorHelpers::FObjectFinder<UDataTable> BP_ItemDB(*BP_ITEMDB);
	ItemDB = BP_ItemDB.Object;
}

And this is my error:

2>  [1/4] MeatGameState.cpp
2>C:\Program Files\Epic Games\UE_4.24\Engine\Source\Runtime\CoreUObject\Public\UObject/ConstructorHelpers.h(110): error C2664: 'void ConstructorHelpers::ValidateObject(UObject *,const FString &,const TCHAR *)': cannot convert argument 1 from 'T *' to 'UObject *'
2>          with
2>          [
2>              T=UDataTable
2>          ]

Im not really sure why this is happening or what Im doing wrong. Thanks for any help.

Just tried it and I got the same error

omg… lol. I thought I had it in my head file but no. Now, it works. Really gotta love ue4 and c++ errors… uuuuuuugh.

Did you try something like this?

 AMeatGameState::AMeatGameState()
 {
     const FString BP_ITEMDB = "DataTable'/Game/Data/ItemDB.ItemDB'";
     ItemDB = ConstructorHelpers::FObjectFinder<UDataTable>(*BP_ITEMDB).Object;
 }
1 Like

Actually, there is another thing that came to my mind. The error might be caused because there is no include for the UDataTable class.

Do you have this on top of your .cpp file?

#include "Engine/DataTable.h"
1 Like

Did you try with the include?

1 Like

Actually, there is another thing that came to my mind. The error might be caused because there is no include for the UDataTable class.

Do you have this on top of your .cpp file?

#include "Engine/DataTable.h"
1 Like

I converted this comment into an answer. If you mark it as resolved, this will help other members of the community to find the right answers.
I’m glad that we worked it out.

You are very welcome. I converted the comment into an answer.

If you don’t mind adding this as an answer comment. I can mark this as answered. Thanks again. It’s always the little things lol

yeah that reply was to just seting itemDb to the construction helper and skipping creating the variable BP_ITEMDB

it may be your asset, the resource stored in BP_ITEMDB cannot be loaded as a UObject, so it mentioned that convert fail