Reimport Data table

I am trying to mimic what happens when the user right clicks on a data table and clicks on “reimport”.

Being exposed to blueprints, inside a UBlueprintFunctionLibrary, it looks like:
.h


#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Engine/DataTable.h"
#include "MyLibrary.generated.h"



UCLASS()
class ZZ_API UMyLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
	
		//Reimport DataTable
		UFUNCTION(BlueprintCallable, Category = "Test")
		static void ReimportDT(UDataTable* DataTable);
};

.cpp


#include "MyLibrary.h"
#include "CoreMisc.h"
#include "FileHelper.h"

void UMyLibrary::ReimportDT(
	UDataTable* DT) 
{
	DT->
}

Now I’m not sure how to proceed. I’m not finding any obvious reimport function, so what happens?

Here’s an update.

Current code:


void UMyLibrary::ReimportDT(
	UDataTable* DT)
{

	FString csvFile = FString("C:\\TestDir\\csvFile.csv");
	if (FPaths::FileExists(csvFile))
	{
		//Print that path exists
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, TEXT("Path exists"));

		//create string variable.
		FString FileContent;
		FFileHelper::LoadFileToString(FileContent, *csvFile);
		
			//Print if  loadfile returns true
			//GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, TEXT("Load file returned true"));
		

		//Print content of FileContent.
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, FileContent);

		//Create table (same as update table?) and save any problems to an array.
		TArray<FString> problems = DT->CreateTableFromCSVString(FileContent);

		//get length of the problems array.
		FString problemsnum = FString::FromInt(problems.Num());

		//print Number of problems.
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, problemsnum);

		//print each problem
		for (int32 Index = 0; Index != problems.Num(); ++Index)
		{
		FString problem = problems[Index];
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, problem);

		}

	}

}

With the current setup, it writes to the csvFile and then printing each member of the updated data table, it does indeed import the csv file.
(NewRow_20 is the new member)

DTRows.png

However, if I open the data table in the content browser, or click on its tab if it’s already open, the engine crashes.

If I change -



		FFileHelper::LoadFileToString(FileContent, *csvFile);
		
			//Print if  loadfile returns true
			//GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, TEXT("Load file returned true"));
		


To -


		if (FFileHelper::LoadFileToString(FileContent, *csvFile)) {

			//Print if  loadfile returns true
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, TEXT("Load file returned true"));
		}

Then the engine does not crash, but does also not reimport the DataTable.

I feel like I am getting close, but am obviously missing something. There’s a “ReimportDataTableFactory”, with the following code:


#include "CoreMinimal.h"
#include "UObject/ObjectMacros.h"
#include "Factories/CSVImportFactory.h"
#include "EditorReimportHandler.h"
#include "ReimportDataTableFactory.generated.h"

UCLASS()
class UNREALED_API UReimportDataTableFactory : public UCSVImportFactory, public FReimportHandler
{
	GENERATED_UCLASS_BODY()

	//~ Begin FReimportHandler Interface
	virtual bool FactoryCanImport( const FString& Filename ) override;
	virtual bool CanReimport( UObject* Obj, TArray<FString>& OutFilenames ) override;
	virtual void SetReimportPaths( UObject* Obj, const TArray<FString>& NewReimportPaths ) override;
	virtual EReimportResult::Type Reimport( UObject* Obj ) override;
	virtual int32 GetPriority() const override;
	//~ End FReimportHandler Interface
};

Do I need to use that?

Then there is also the matter of the directory. Right now it’s a hard coded string. The first time I reimported the data table through the content browser, I had to select the file but after that it always uses the same file. How can I get that directory?

There’s the “DataTableCSV” class, which has the following function and data:


class FDataTableImporterCSV
{
public:
	FDataTableImporterCSV(UDataTable& InDataTable, FString InCSVData, TArray<FString>& OutProblems);

	~FDataTableImporterCSV();

	bool ReadTable();

private:
	UDataTable* DataTable;
	FString CSVData;
	TArray<FString>& ImportProblems;
};

Where I think the CSVData is the directory.

You could find out how the reimport button does its thing by just searching “Reimport” in the engine source. Like most things in the engine it’s like very straight forward once you found the correct api… :smiley:

Yes, that’s what I’ve been thinking. There’s probably just a function to call, but where? Searching for “reimport” brings up… hundreds of results.
Of course, narrowing it down there’s:

ReimportDataTableFactory

*ReimportCSV(Uobject )
I’m thinking it’s the ReimbortCSV function, inside CSVImportFactory.


/**
 * Factory for importing table from text (CSV)
 */

#pragma once

#include "CoreMinimal.h"
#include "UObject/ObjectMacros.h"
#include "Curves/RichCurve.h"
#include "Factories/Factory.h"
#include "Factories/ImportSettings.h"
#include "CSVImportFactory.generated.h"

DECLARE_LOG_CATEGORY_EXTERN(LogCSVImportFactory, Log, All);

/** Enum to indicate what to import CSV as */
UENUM()
enum class ECSVImportType : uint8
{
	/** Import as UDataTable */
	ECSV_DataTable,
	/** Import as UCurveTable */
	ECSV_CurveTable,
	/** Import as a UCurveFloat */
	ECSV_CurveFloat,
	/** Import as a UCurveVector */
	ECSV_CurveVector,
	/** Import as a UCurveLinearColor */
	ECSV_CurveLinearColor,
};

USTRUCT()
struct FCSVImportSettings
{
	GENERATED_BODY()

	FCSVImportSettings();

	UPROPERTY()
	UScriptStruct* ImportRowStruct;

	UPROPERTY()
	ECSVImportType ImportType;

	UPROPERTY()
	TEnumAsByte<ERichCurveInterpMode> ImportCurveInterpMode;
};

UCLASS(hidecategories=Object)
class UNREALED_API UCSVImportFactory : public UFactory, public IImportSettingsParser
{
	GENERATED_UCLASS_BODY()

	//~ Begin UFactory Interface
	virtual FText GetDisplayName() const override;
	virtual UObject* FactoryCreateText( UClass* InClass, UObject* InParent, FName InName, EObjectFlags Flags, UObject* Context, const TCHAR* Type, const TCHAR*& Buffer, const TCHAR* BufferEnd, FFeedbackContext* Warn ) override;
	virtual bool DoesSupportClass(UClass * Class) override;
	virtual bool FactoryCanImport(const FString& Filename) override;
	virtual	IImportSettingsParser* GetImportSettingsParser() override { return this; }


	/* Reimport an object that was created based on a CSV */
	bool ReimportCSV(UObject* Obj);
	
	/**
	 * IImportSettings interface
	 */
	virtual void ParseFromJson(TSharedRef<class FJsonObject> ImportSettingsJson) override;

protected:
	virtual TArray<FString> DoImportDataTable(class UDataTable* TargetDataTable, const FString& DataToImport);
	virtual TArray<FString> DoImportCurveTable(class UCurveTable* TargetCurveTable, const FString& DataToImport, const ERichCurveInterpMode ImportCurveInterpMode);
	virtual TArray<FString> DoImportCurve(class UCurveBase* TargetCurve, const FString& DataToImport);

private:
	/* Reimport object from the given path*/
	bool Reimport(UObject* Obj, const FString& Path  );

	UPROPERTY()
	FCSVImportSettings AutomatedImportSettings;
};


But then there’s the question, how do I use it? Did I mention I don’t know any cpp? Do I have to #include something? Do I have to construct this class? I have no idea.

Oh, I meant to search specifically for “Reimport” (including quotes) because then it brings up the string where this gui button is constructed.
Seems to be as simple as this:



void UMyLibrary::ReimportDT(UDataTable* DT)
{
	FReimportManager::Instance()->Reimport(DT);
}


Not sure though.

I wish. It seems right though but I am getting an error:

In my class, I am including:
include “MyLibrary.h”
include “CoreMisc.h”
include “FileHelper.h”
include “Paths.h”
include “Engine.h”
include “UnrealEd.h”

The declaration of Instance() is inside EditorReimportHandler.h


#include "CoreMinimal.h"
#include "UObject/GCObject.h"
#include "Containers/ArrayView.h"

class FReimportHandler;

/** Reimport manager for package resources with associated source files on disk. */
class FReimportManager : FGCObject
{
public:
	/**
	 * Singleton function, provides access to the only instance of the class
	 *
	 * @return	Singleton instance of the manager
	 */
	UNREALED_API static FReimportManager* Instance();

And the Definition is inside Editor.cpp



FReimportManager* FReimportManager::Instance()
{
	static FReimportManager Inst;
	return &Inst;
}

I don’t know what I am missing.

It should be enough to in include EditorReimportHelper.h instead of UnrealEd.h, did you add UnrealEd to the list of dependencies in your Build.cs?

I did not add UnrealEd to dependencies. First time I open the build.cs file and now “UnrealEd” is added to PublicDependencyModuleNames array.

But as I try to Include EditorReimportHelper.h, #Include is underlined red and says “cannot open source file “EditorReimportHelper.h””
By the way, the includes are in .cpp, I hope that is correct.

If you just want to replace the data in an existing Data Table with data from a new CSV file, just load the CSV file to a string and call CreateTableFromCSVString on the UDataTable.

Also remember that re-importing data is an editor-only thing, so you’ll need it to be in the editor module for your game so that you can still compile standalone (that link may be a bit out-of-date now, but hopefully you’ll get nice deprecation warnings rather than errors). That said, since this doesn’t add any editor modules as dependencies, you might just be able to wrap the re-import logic in your code with #if WITH_EDITOR.

My intention is to only recreate the data table from csv in pie, not in a built game. So CreateTableFromCSVString just won’t work unless it’s with the WITH_EDITOR or module thing?
I tried to wrap the functions with #if WITH_EDITOR but still crashes when looking at the data table.
As for Editor module, well. It didn’t go well. In fact the project became unusable so I deleted it and started a new one.

My intent is to build a ui widget, where I can ‘design’ item data, something like Auno.org - Item Database - Search but instead of begin used for searching, it then takes the fields, builds a string based on the data struct, appends it to the csv file… and then I guess click reimport manually.

PIE is fine as that’s in the editor, just as long as you don’t need to do it in a cooked game.

It shouldn’t do. What’s the callstack of the crash?

Can you post your function again now that you’re using CreateTableFromCSVString?

Call stack:


[2017.06.28-20.36.37:306][149]LogWindows: Windows GetLastError: The operation completed successfully. (0)
[2017.06.28-20.36.37:735][149]LogCrashTracker: 


[2017.06.28-20.36.37:735][149]LogCrashTracker: 


[2017.06.28-20.36.37:735][149]LogWindows:Error: === Critical error: ===
[2017.06.28-20.36.37:735][149]LogWindows:Error: 
[2017.06.28-20.36.37:735][149]LogWindows:Error: Assertion failed: Count >= 0 [File:d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\public\Containers/UnrealString.h] [Line: 377] 
[2017.06.28-20.36.37:735][149]LogWindows:Error: 
[2017.06.28-20.36.37:735][149]LogWindows:Error: 
[2017.06.28-20.36.37:735][149]LogWindows:Error: 
[2017.06.28-20.36.37:735][149]LogWindows:Error: Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0xffffffff
[2017.06.28-20.36.37:735][149]LogWindows:Error: 
[2017.06.28-20.36.37:735][149]LogWindows:Error: VCRUNTIME140.dll!0x00000000EEC1C447
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-CoreUObject.dll!0x00000000E58111E3
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-CoreUObject.dll!0x00000000E57B88FA
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-PropertyEditor.dll!0x00000000D49F7E0F
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-PropertyEditor.dll!0x00000000D49FEB01
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-PropertyEditor.dll!0x00000000D48FD12D
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-PropertyEditor.dll!0x00000000D4756D28
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-PropertyEditor.dll!0x00000000D4759EF9
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-PropertyEditor.dll!0x00000000D48B9665
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-Slate.dll!0x00000000E1A4DB57
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-Slate.dll!0x00000000E1A54B61
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-Slate.dll!0x00000000E1C97177
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC514F
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-Slate.dll!0x00000000E1C08D37
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC55FA
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC4108
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC390C
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-Slate.dll!0x00000000E1C08A59
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC55FA
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC4108
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC390C
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC390C
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC55FA
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC4108
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC390C
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-Slate.dll!0x00000000E1C08D37
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC55FA
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC4108
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC55FA
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC4108
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC55FA
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-Slate.dll!0x00000000E1C8677D
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC390C
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-Slate.dll!0x00000000E1C08A59
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC390C
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-Slate.dll!0x00000000E1C08A59
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-PropertyEditor.dll!0x00000000D494B71E
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC55FA
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC4108
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC390C
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-Slate.dll!0x00000000E1CB64D2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC55FA
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC4108
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC55FA
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC4108
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-Slate.dll!0x00000000E1C08D37
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC390C
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC55FA
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC4108
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC390C
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC390C
[2017.06.28-20.36.37:735][149]LogWindows:Error: UE4Editor-Slate.dll!0x00000000E1C08A59
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC390C
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-Slate.dll!0x00000000E1C08A59
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC3FC3
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC55FA
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC4108
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC390C
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC55FA
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-Slate.dll!0x00000000E1C8677D
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC3FC3
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC390C
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC55FA
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC4108
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC390C
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC390C
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-Slate.dll!0x00000000E1C08A59
[2017.06.28-20.36.37:736][149]LogWindows:Error: UE4Editor-SlateCore.dll!0x00000000E5CC51A2
[2017.06.28-20.36.37:736][149]LogWindows:Error: 
[2017.06.28-20.36.37:745][149]LogExit: Executing StaticShutdownAfterError
[2017.06.28-20.36.37:747][149]LogWindows: FPlatformMisc::RequestExit(1)
[2017.06.28-20.36.37:747][149]Log file closed, 06/28/17 22:36:37

Code, inside a UBlueprintlibrary:

.h


	//Reimport DataTable
	UFUNCTION(BlueprintCallable, Category = "Test")
	static void ReimportDT(UDataTable* DataTable);

.cpp



#include "MyLibrary.h"
#include "CoreMisc.h"
#include "FileHelper.h"
#include "Paths.h"
#include "Engine.h"

void UMyLibrary::ReimportDT(UDataTable* DT)
{

	FString csvFile = FString("C:\\TestDir\\csvFile.csv");
	if (FPaths::FileExists(csvFile))
	{

		//Print that path exists
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, TEXT("Path exists"));

		//create string variable. Load file to string.
		FString FileContent;
		if (FFileHelper::LoadFileToString(FileContent, *csvFile))
		{
			//Print if loadfiletostring returns true
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, TEXT("Load file returned true"));

		}


		//Print content of FileContent.
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, FileContent);

		//Create table and save any problems to an array.
		TArray<FString> problems = DT->CreateTableFromCSVString(FileContent);

		//get length of the problems array.
		FString problemsnum = FString::FromInt(problems.Num());
		//print Number of problems.
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, problemsnum);

		//print each problem
		for (int32 Index = 0; Index != problems.Num(); ++Index)
		{
			FString problem = problems[Index];
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, problem);

		}
	}
}

It does print all new members.

Doesn’t really help I’m afraid. I don’t use installed builds so I’m not sure how exactly they work with debug symbols (do you have them installed?), but you might get better results from a source build.

It prints each line as a problem? What does your CSV data look like, and what struct are you using with the Data Table?

I don’t even know what all that meant, even less having debug symbols. I’ll look into it but it will take some time for me to get that perhaps working.

Sorry, what I meant was that if I after reimporting, in blueprints iterate through the data table, it prints each member as expected. It’s just that looking at the data table crashes it. I can write to the csv and manually reimport (content browser) successfully so there shouldn’t be any syntax problems.

To be specific, the struct is like this:
—,Bool,String,int,Names Array
NewRow__,“False”,“”,“0”,“(”“1"”)"

Would it help if I uploaded this project? It’s almost empty but is 1.3GB for some reason. There’s a file in projectname\v15\ipch\AutoPCH\ZZ-fa7ad593\MYLIBRARY-e18e6ef1 named “MYLIBRARY.ipch” (name of my Ublueprintlibrary) that is 750 mb big. Can I delete that?

I don’t know what that file is, but you only need the Config, Content, and Source folders along with the .uproject file in order to distribute a working project.

50 MB seems more reasonable. also the csv file, but in cpp it’s hardcoded to be in a C:\TestDir folder.
As it is setup now, the blueprint executes the “reimportDT” function on begin play.

Some symptoms I’ve found

Main symptom: CreateTableFromCSVString if CSV file has equal or greater members, will crash the engine when looking at the data table. (note: iterating through the updated DT shows updated members).
However: CreateTableFromCSVString and then closing the project and opening the project, looking at the data table does not show the new members.

No crash: Having more members in the DataTable than the CSV file, CreateTableFromCSVString will not cause a crash.
However: The Data table must be reopened to update.

Since it’s me who have coded, I don’t know if its my code that’s bad or if I have found a few bugs.

The project you uploaded works fine for me (tested in 4.16 and Main). If I open the map, PIE, then open the Data Table editor, nothing crashes.

The data table looks like:
NewRow
NewRow_0
NewRow_1

and the CSV file is the same, except for a NewRow_10 being the last key.
If you remove one of the data table members, it will crash. Oh also ensure the NewBlueprint is in the map, or open the “map” map. I forgot to change that to default. You will see white text printed when the cpp code is executed.

Edit;
I am noticing some different symptoms now. I just updated the 4.16 version.
If the data table is closed, and I CreateTableFromCSVString, and the CSV file had more members, then open the DT it will not crash.
But if the data table is open while CreateTableFromCSVString, it will. Now even if the CSV has less members.

Addendum;
Crash or no crash, closing and reopening the editor after CreateTableFromCSVString doesn’t actually save the data table. Its data is back to what it was before.

You’ve only edited the asset in memory. You’ll need to save the asset if you want to persist the changes (FEditorFileUtils::PromptForCheckoutAndSave would be one way to do that).