# How to load the CSV DataTable dynamically?

**URL:** <https://forums.unrealengine.com/t/how-to-load-the-csv-datatable-dynamically/303420>\
**Category:** Community & Industry Discussion\
**Tags:** datatable, csv, unreal-engine, question\
**Created:** [January 9, 2015, 4:16am UTC](https://forums.unrealengine.com/t/how-to-load-the-csv-datatable-dynamically/303420 "2015-01-09T04:16:58Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_e281dc471](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e281dc471](https://forums.unrealengine.com/u/anonymous_user_e281dc471)\
**Post date:** [January 9, 2015, 4:16am UTC](https://forums.unrealengine.com/t/how-to-load-the-csv-datatable-dynamically/303420/1 "2015-01-09T04:16:58Z")

</div>

Hi,  
How to load the CSV DataTable dynamically? I want to download csv from my server and update game data… Is it possible?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_eef88731](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_eef88731](https://forums.unrealengine.com/u/anonymous_user_eef88731)\
**Post date:** [September 24, 2015, 5:59am UTC](https://forums.unrealengine.com/t/how-to-load-the-csv-datatable-dynamically/303420/2 "2015-09-24T05:59:31Z")

</div>

I don’t know how to download a file from the server. But once you download the csv file, you can update dynamically using something similar below

```
FString csvFile = FPaths::GameContentDir() + "Downloads\\DownloadedFile.csv";
		if (FPaths::FileExists(csvFile ))
		{
			FString FileContent;
			// the csv file
			FFileHelper::LoadFileToString(FileContent, *csvFile );
			TArray<FString> problems = YourDataTable->CreateTableFromCSVString(FileContent);

			if (problems.Num() > 0)
			{
				for (int32 ProbIdx = 0; ProbIdx < problems.Num(); ProbIdx++)
				{		
                                            //Log the errors
				}
			}
			else
			{
				//Updated Successfully
			}
		}

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4c483198](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4c483198](https://forums.unrealengine.com/u/anonymous_user_4c483198)\
**Post date:** [November 3, 2015, 7:35pm UTC](https://forums.unrealengine.com/t/how-to-load-the-csv-datatable-dynamically/303420/3 "2015-11-03T19:35:57Z")

</div>

Hi,  
do you know if it is possible to do this same using only BP?  
So I’ve several csv files in my game folder. I just want to load one of them depending on game state, and I don’t want to use c++ at all.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b9532c9a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b9532c9a](https://forums.unrealengine.com/u/anonymous_user_b9532c9a)\
**Post date:** [November 3, 2015, 9:16pm UTC](https://forums.unrealengine.com/t/how-to-load-the-csv-datatable-dynamically/303420/4 "2015-11-03T21:16:01Z")

</div>

Thank you for your request. There is already a feature request in our system, UE-20507, to be considered by the development staff.

---

<div class="post-metadata">

**Author:** ![Genova](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Genova](https://forums.unrealengine.com/u/Genova)\
**Post date:** [February 5, 2016, 10:17pm UTC](https://forums.unrealengine.com/t/how-to-load-the-csv-datatable-dynamically/303420/5 "2016-02-05T22:17:08Z")

</div>

Hey ,

Are there been any progress on that? I’d like to import .csv files on runtime aswel.

Thanks

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [February 8, 2016, 4:23pm UTC](https://forums.unrealengine.com/t/how-to-load-the-csv-datatable-dynamically/303420/6 "2016-02-08T16:23:42Z")

</div>

Hey -

The feature request that mentioned is still currently open for considersation however I can’t say when/if it will be incorporated into the engine. I have updated the request post to indicate that this is still an issue for the community.

Cheers

---

<div class="post-metadata">

**Author:** ![Acrossfy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Acrossfy](https://forums.unrealengine.com/u/Acrossfy)\
**Post date:** [February 6, 2017, 8:07pm UTC](https://forums.unrealengine.com/t/how-to-load-the-csv-datatable-dynamically/303420/7 "2017-02-06T20:07:50Z")

</div>

CreateTableFromCSVString is working only in editor. So seems like there is no any solution for this (built-in solution of course).

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8d683ec41](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8d683ec41](https://forums.unrealengine.com/u/anonymous_user_8d683ec41)\
**Post date:** [February 15, 2017, 7:39am UTC](https://forums.unrealengine.com/t/how-to-load-the-csv-datatable-dynamically/303420/8 "2017-02-15T07:39:19Z")

</div>

So CreateTableFromCSVString doesn’t update itself on a live compiled game? How about using a plugin like VaRest and implement the data on the fly?

---

<div class="post-metadata">

**Author:** ![Hyperloop](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hyperloop/32/1203427_2.png) [@Hyperloop](https://forums.unrealengine.com/u/Hyperloop)\
**Post date:** [May 2, 2017, 3:39pm UTC](https://forums.unrealengine.com/t/how-to-load-the-csv-datatable-dynamically/303420/9 "2017-05-02T15:39:02Z")

</div>

Not 100% sure but it may be worth checking 's victory plugin. I seem to recall some better file IO support in there.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e2ade227](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e2ade227](https://forums.unrealengine.com/u/anonymous_user_e2ade227)\
**Post date:** [January 14, 2018, 5:33pm UTC](https://forums.unrealengine.com/t/how-to-load-the-csv-datatable-dynamically/303420/10 "2018-01-14T17:33:55Z")

</div>

We need some update on this. This is the best way to tweak values in the game such as rate of fire, bullet spread etc. I would like my QA to play the game-\> modify values in excel → do a keypress in game to update rate of fire and see how it feels.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b4cb54ba](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b4cb54ba](https://forums.unrealengine.com/u/anonymous_user_b4cb54ba)\
**Post date:** [February 20, 2018, 2:27am UTC](https://forums.unrealengine.com/t/how-to-load-the-csv-datatable-dynamically/303420/11 "2018-02-20T02:27:02Z")

</div>

So the problem is that the code that reads this in the data table class is all in bed with the rest of the editor. You can’t just comment out the Editor Only ifdefs there (I tried it), it calls functions on the asset base classes that are only in the editor, and support functions that are only in editor, etc. It quickly spirals out of control. In order to support this in a standalone game, they’d either have to rewrite a version of the import code that doesn’t use any of the editor support classes or code, or they’d have to move a _lot_ of stuff out of editor into the base engine. Sigh. I hope this is a big boat, because lots of people are in it.

---

<div class="post-metadata">

**Author:** ![dg-ani](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dg-ani](https://forums.unrealengine.com/u/dg-ani)\
**Post date:** [August 7, 2019, 5:22pm UTC](https://forums.unrealengine.com/t/how-to-load-the-csv-datatable-dynamically/303420/12 "2019-08-07T17:22:16Z")

</div>

I’d also like to see this. It’s been a few years, any updates?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b4cb54ba](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b4cb54ba](https://forums.unrealengine.com/u/anonymous_user_b4cb54ba)\
**Post date:** [August 7, 2019, 9:15pm UTC](https://forums.unrealengine.com/t/how-to-load-the-csv-datatable-dynamically/303420/13 "2019-08-07T21:15:31Z")

</div>

In the end, I wrote my own. Here’s some code that may be helpful, extracted from some early Horde Mode prototyping I did for Earthfall. Naturally all the Earthfall specific stuff is useless, but it shows how to create a datatable in code, and parse a CSV into records and add them:

```
/*
    	This function reads in the csv file provided from Content/HordeMode/filename and parses it into
    	a datatable. The first column is the rowkey. Tables aren't indexed by row index in Unreal, but by a key, so they may be in any order.
    */
    bool ADirector::LoadHordeScript(FString filename)
    {
    	int rowsAdded = 0;
    	if (filename.IsEmpty())
    		return false;
    	// Create a new datatable based on the wave struct
    	UClass* DataTableClass = UDataTable::StaticClass();
    	ScriptedLines = NewObject<UDataTable>(this, DataTableClass, FName(TEXT("HordeModeDataTable")));	// Blow away any previous table
    	ScriptedLines->RowStruct = FScriptLineDescriptorRow::StaticStruct();
    
    	loopCounters.Reset(); // Clear anything we might be in the middle of
    	ScriptCallStack.Reset();
    
    	FString csvFile = FPaths::ProjectContentDir() + "HordeMode/" + filename;
    	if (FPaths::FileExists(csvFile))
    	{
    		TArray<FString> lines;
                    // Load the entire file into an array of strings
    		FFileHelper::LoadANSITextFileToStrings(*csvFile, NULL, lines);
    		const UEnum* SpawnTypeEnumPtr = FindObject<UEnum>(ANY_PACKAGE, TEXT("ESpawnType"), true);
    		const UEnum* LineTypeEnumPtr = FindObject<UEnum>(ANY_PACKAGE, TEXT("EScriptLineType"), true);
    		FScriptLineDescriptorRow row;
    		if (!SpawnTypeEnumPtr || !LineTypeEnumPtr)
    		{
    			UE_LOG(Earthfall_Lore, Error, TEXT("Can't find enum for ESpawnType or EScriptLineType"));
    			return false;
    		}
    
    
                    // Parse each string into a record
    		for (int i = 1; i < lines.Num(); i++)
    		{
    			FString aString = lines[i];
    
    			TArray<FString> stringArray = {};

                            // break string into tokens broken up by commas
    			aString.ParseIntoArray(stringArray, TEXT(","), false);
    			if (stringArray.Num() == 0)
    				continue;	// Skip empty lines
    			FString LineLable = stringArray[0];
    			// CSV files will entry if it has a ',' character in it. So if your ; comment has a , you have to look for ";   
    			if ((LineLable.Len() == 0) || LineLable.StartsWith("\";") || LineLable.StartsWith(";"))
    				continue;	// Skip comments or lines with no label
                            // Validate number of expected tokens
    			if (stringArray.Num() < 13)
    			{
    				UE_LOG(Earthfall_Lore, Warning, TEXT("LoadHordeScript skipping non-commented line %d with only %d columns"), i, stringArray.Num());
    				continue;
    			}
                            // Parse all the tokens into a struct
    			row.LineType = (EScriptLineType)LineTypeEnumPtr->GetValueByNameString(*stringArray[1]);
    			row.SpawnType = (ESpawnType)SpawnTypeEnumPtr->GetValueByNameString(*stringArray[2]);
    			row.Min = FCString::Atoi(*stringArray[3]);
    			row.Max = FCString::Atoi(*stringArray[4]);
    			row.PlayAudio = (FCString::Stricmp(*stringArray[5], TEXT("TRUE")) == 0);
    			row.HealthMult = FCString::Atof(*stringArray[6]);
    			row.DamageMult = FCString::Atof(*stringArray[7]);
    			row.SpeedMult = FCString::Atof(*stringArray[8]);
    			row.DelayAfterLine = FCString::Atof(*stringArray[9]);
    			row.ShowCountdown = (FCString::Stricmp(*stringArray[10], TEXT("TRUE")) == 0);
    			row.NumericData = FCString::Atof(*stringArray[11]);
    			row.StringData = FName(*stringArray[12]);
                            // Add a new row to the datatable
    			ScriptedLines->AddRow(FName(*stringArray[0]), row);
    			rowsAdded++;
    // if (i == 1)
    // {
    // ScriptedLine = row;	// Starting wave
    // }
    		}
    	}
    	else
    	{
    		UE_LOG(Earthfall_AI, Error, TEXT("LoadHordeScript File %s not found!"), *csvFile);
    		return false;
    	}
    	ScriptedLine.DelayAfterLine = 0;
    	return (rowsAdded > 0);
    }

```

---

<div class="post-metadata">

**Author:** ![Estape](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/estape/32/1007455_2.png) [@Estape](https://forums.unrealengine.com/u/Estape)\
**Post date:** [September 25, 2019, 5:51pm UTC](https://forums.unrealengine.com/t/how-to-load-the-csv-datatable-dynamically/303420/14 "2019-09-25T17:51:58Z")

</div>

This code apply on .h file or .cpp file?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b4cb54ba](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b4cb54ba](https://forums.unrealengine.com/u/anonymous_user_b4cb54ba)\
**Post date:** [September 25, 2019, 7:40pm UTC](https://forums.unrealengine.com/t/how-to-load-the-csv-datatable-dynamically/303420/15 "2019-09-25T19:40:34Z")

</div>

Well that was in my .cpp file. You’ll need to extract the relevant bits for your use. It’s just an example of how I made a new table, set up the RowStruct that defines a row, in the csv and parsed each line into an instance of that struct and added them to the datatable. Your code will of course have to use your own structure based on your data, but the framework should be the same.
