Hi all!
I have a TMap declared as follow: TMap<FString, UDataTable>* providerCatalogs;
All my code works, but, if i do this: catalogs->Add(providerName, *dataTable);
i get this error:
“Error 1 error C2248: ‘UDataTable::UDataTable’ : no se puede obtener acceso al miembro private miembro declarado en la clase ‘UDataTable’ M:\Epic Games\4.8\Engine\Source\Runtime\Core\Public\Containers\Map.h 59 1 MyShop”
This is my full code:
Providers.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMisc.h"
#include "ProviderCatalog.h"
#include "GameFramework/Actor.h"
#include "Providers.generated.h"
class ProviderCatalogFinder : public IPlatformFile::FDirectoryVisitor
{
virtual bool Visit(const TCHAR* FilenameOrDirectory, bool bIsDirectory);
private:
TMap<FString, UDataTable>* catalogs;
public:
ProviderCatalogFinder(TMap<FString, UDataTable>* providerCatalogs);
};
/**
* The article providers
*/
UCLASS(Blueprintable, BlueprintType)
class MYSHOP_API AProviders : public AActor
{
GENERATED_BODY()
private:
FString PROVIDERS_PATH = "Providers/";
FString PROVIDERS_LIST = "Providers.txt";
TMap<FString, UDataTable>* providerCatalogs;
public:
// Sets default values for this actor's properties
AProviders();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
// Loads the available provider catalogs
void LoadCatalogs();
};
Providers.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyShop.h"
#include "Providers.h"
ProviderCatalogFinder::ProviderCatalogFinder(TMap<FString, UDataTable>* providerCatalogs)
{
catalogs = providerCatalogs;
}
bool ProviderCatalogFinder::Visit(const TCHAR* FilenameOrDirectory, bool bIsDirectory)
{
if (!bIsDirectory)
{
FString file = FString(FilenameOrDirectory);
if (FPaths::GetExtension(file).ToLower() == "csv")
{
FString catalogData;
FString providerName;
FFileHelper::LoadFileToString(catalogData, *file);
TArray<FString> errors;
if (!catalogData.IsEmpty())
{
providerName = FPaths::GetCleanFilename(file);
UE_LOG(LogTemp, Log, TEXT("Processing the catalog of the provider '%s' ..."), *providerName);
UDataTable* dataTable = NewObject<UDataTable>(UDataTable::StaticClass());
dataTable->RowStruct = FProviderCatalog().StaticStruct();
errors = dataTable->CreateTableFromCSVString(catalogData);
if (errors.Num() > 0)
{
UE_LOG(LogTemp, Error, TEXT("There were errors processing the catalog:"));
for (FString error : errors)
{
UE_LOG(LogTemp, Error, TEXT("- %s"), *error);
}
UE_LOG(LogTemp, Error, TEXT("-----------------------------------------"));
}
else
{
UE_LOG(LogTemp, Log, TEXT("Found %i articles in the catalog."), dataTable->GetRowNames().Num());
catalogs->Add(providerName, *dataTable);
}
return true;
}
}
}
return false;
}
// Sets default values
AProviders::AProviders()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AProviders::BeginPlay()
{
Super::BeginPlay();
providerCatalogs = new TMap<FString, UDataTable>();
LoadCatalogs();
}
// Called every frame
void AProviders::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
void AProviders::LoadCatalogs()
{
FString catalogsDir = (FPaths::GameContentDir() + PROVIDERS_PATH);
ProviderCatalogFinder catalogFinder = ProviderCatalogFinder(providerCatalogs);
UE_LOG(LogTemp, Log, TEXT("Loading available provider catalogs from '%s' ..."), *catalogsDir);
FPlatformFileManager::Get().GetPlatformFile().IterateDirectory(*catalogsDir, catalogFinder);
UE_LOG(LogTemp, Log, TEXT("Loaded %i catalogs."), providerCatalogs->Num());
}
Thanks for your assistance .
See ya!