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.
FSapio
(FSapio)
April 11, 2020, 10:20pm
2
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
FSapio
(FSapio)
April 11, 2020, 10:24pm
3
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
FSapio
(FSapio)
April 11, 2020, 10:24pm
4
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
Just tried it and I got the same error
FSapio
(FSapio)
April 11, 2020, 10:27pm
6
Did you try with the include?
1 Like
omg… lol. I thought I had it in my head file but no. Now, it works. Really gotta love ue4 and c++ errors… uuuuuuugh.
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
FSapio
(FSapio)
April 11, 2020, 10:31pm
9
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.
FSapio
(FSapio)
April 11, 2020, 10:33pm
10
You are very welcome. I converted the comment into an answer.
yeah that reply was to just seting itemDb to the construction helper and skipping creating the variable BP_ITEMDB