How can I resolve error C2664: 'ConstructorHelpers::FObjectFinder::FObjectFinder(const ConstructorHelpers::FObjectFinder &)' : cannot convert argument 1 from 'FString' to 'const TCHAR *'?

Hey Guys,

I’m trying to dynamically load a .csv file via code. However I get this error:

error C2664: ‘ConstructorHelpers::FObjectFinder::FObjectFinder(const ConstructorHelpers::FObjectFinder &)’ : cannot convert argument 1 from ‘FString’ to ‘const TCHAR *’

// Code above this is irrelevant

	FString testSong = TEXT("DataTable'/Game/SongData/Arroz/arroz_track_01.SongNoteData'");
	generateNotes(testSong);
}

std::vector<ANoteSphere> ASongMode::generateNotes(FString song)
{
	UDataTable* songData;
	ConstructorHelpers::FObjectFinder<UDataTable> SongLookupData_BP(song);
	songData = SongLookupData_BP.Object;

	std::vector<ANoteSphere> noteSpheres;

	return noteSpheres;
}

That’s the code I’m using that has to do with the error. Am I missing a .h file for DataTables? Or is there something else causing this error? I am a total UE4 noob so I’m still trying to wrap my head around some concepts…

First as error states you need to use “const TCHAR*” instead of FString.

Also try avoid std types, try using TArray or TMap insted, doing that you sure that game will work in all platforms and compiles supported by UE4

#The Answer

 ConstructorHelpers::FObjectFinder SongLookupData_BP(*song); //note the *

#Reason

inner data of FString accessed as TCHAR * is the * operator

*FString = TCHAR

(*song);

Enjoy!

Had no idea about TArray, so I’ll look into that!