Driving Gameplay with Data from Excel

[=;223939]
When I try the triple quotes in my datatable, it crashes the editor instantly.
[/]

Hi

I had the same problem but in my case it wasn’t the trible quotes. At first I thought it was but it turned out that the editor could not find the referenced asset, and crashed.
So you might want to check the path to your asset within your trible quotes. Try rightclicking the asset in the content browser of the editor, click “Copy Reference” and paste the whole thing in your datatable, that way you avoid any kind of spelling error.

Hope this helps

JazzMalar

[=JazzMalar;224024]
Hope this helpsr
[/]

Yup! That works great! I can now reference assets, materials and static meshs.

I’m still confused as to why its requiring triple quotes. It works against all the very little I know about programming!

The following is mere speculation.
I am fairly certain the problem lies with the apostroph (’) in the asset link. Most probably the parser gets tricked into thinking the string is finished there and fails because - well - the string is not really finished.
So what’s the most obvious solution? You surround the string in question with doublequotes so the parser knows where it starts and where it ends.
But now you have another problem, apparently somewhere in the process the doublequotes are truncated before the real parsing even starts (most probably due to some casting mechanism when reading the string). So we need to tell the parser somehow that we want the doublequotes to stay. Surrounding every doublequote with doublequotes will do exactly that. The casting mechanism will then end up with “asdfasdf’assetlink’” instead of asdf’assetlink’.

One thing I noticed - even though my DataTable in the Content Browser shows " ‘AssetType’ Path/To/Asset " (Space added for readability), rather than just “Path/To/Asset” as the official documentation tells me it should, it still works! So this needs revising either in the documentation or in the Content Browser.

Epics was able to reproduce the issue I described (some texture2d assets read from datatables are not displayed until you right click them and click copy reference) and opened an issue about it (UE-11024).
Let’s hope they find something.

https://answers.unrealengine.com/questions/161369/why-do-i-have-to-copy-asset-references-to-my-data.html

Has anyone been able to get this working recently? I’m on 4.7.3 and when I import my CSV I’m getting “none” values for my actor class. I copy/pasted directly from “copy reference” to my spreadsheet and added double quotes to the beginning and end of the path. I tried triple quotes that was mentioned earlier but none of that worked. If I set the variable in the blueprint structure to string (from actor class) the path appears properly.

I JUST got it working! I spent hours trying to figure out what was wrong!!!

As mentioned above, the fix is to select your asset and “Copy reference”, then paste that into your CSV data table within triple quotes.
Make sure your asset witihn the struct is reference by a TAssetPtr<>()

Apparently, and this is NOT documented, the assets have a file extension which needs to be included in the reference path. is my CSV file:



,CreatureName,MeleeDamage,RangedDamage,Range,MovementSpeed,Health,Armor,Portrait,FlavorText
0,Knights,2,0,0,8,20,1,"""Texture2D'/Game/Assets/Textures/Characters/KnightPortrait.KnightPortrait'""",We are the knights who say nay.
1,Peasants,1,0,0,6,10,0,"""Texture2D'/Game/Assets/Textures/Characters/PeasantPortrait.PeasantPortrait'""","Herp de derp, into the breach sir?"
2,Archers,1,2,12,5,10,0,"""Texture2D'/Game/Assets/Textures/Characters/ArcherPortrait.ArcherPortrait'""",Arrows Away!


is my struct:



/**
* These are the per creature properties which we will use to initialize a creature.
*/
USTRUCT(BlueprintType)
struct FCreatureData : public FTableRowBase
{
	GENERATED_USTRUCT_BODY()

public:
	//FCreatureData();

	//This is the creature ID lookup. Same as name.
	//UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CreatureData")
	//	int32 CreatureID;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CreatureData")
		FString CreatureName;

	/** This is how much damage the cretaure does in a melee attack */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CreatureData")
		int32 MeleeDamage;

	/** This is how much damage the creature does in a ranged attack */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CreatureData")
		int32 RangedDamage;

	/** This is how far the creature can shoot its ranged weapon */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CreatureData")
		int32 Range;

	/** This is how fast the creature can move across the landscape */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CreatureData")
		int32 MovementSpeed;

	/** This is how much health the creature is allowed to have */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CreatureData")
		int32 Health;

	/** This is how much armor the creature has. */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CreatureData")
		int32 Armor;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Transient, Category = "CreatureData")
		TAssetPtr<UTexture2D> Portrait;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Transient, Category = "CreatureData")
		FString FlavorText;


};


Header File:



UCLASS()
class UMageMaster2Instance : public UGameInstance
{
	GENERATED_BODY()

public:

	UMageMaster2Instance(const FObjectInitializer& ObjectInitializer);

	//A persistent turn counter
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Game Data")
	int32 turnCount = 0;

	/*Fetches all unit and creature data for the given unit ID.
	@param UnitID - The unit ID to lookup
	@param OutUnitData - The unit template data
	@param OutCreatureData - The creature template data
	@return true if we were able to find a valid unit, false if not.
	*/
	UFUNCTION(BlueprintCallable, Category = "Unit")
		bool GetUnitData(int32 UnitID, FUnitData& OutUnitData, FCreatureData& OutCreatureData);

private:
	UPROPERTY()
		UDataTable* UnitLookupTable;

	UPROPERTY()
		UDataTable* CreatureLookupTable;

};


**.CPP file:
**



#include "MageMaster2.h"

UMageMaster2Instance::UMageMaster2Instance(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
	ConstructorHelpers::FObjectFinder<UDataTable> UnitDataTable(TEXT("/Game/Assets/GameData/UnitData"));
	ConstructorHelpers::FObjectFinder<UDataTable> CreatureDataTable(TEXT("/Game/Assets/GameData/CreatureData"));

	UnitLookupTable = UnitDataTable.Object;
	CreatureLookupTable = CreatureDataTable.Object;

}

bool UMageMaster2Instance::GetUnitData(int32 UnitID, FUnitData& OutUnitData, FCreatureData& OutCreatureData)
{
	bool a = false, b = false;

	OutUnitData = *UnitLookupTable->FindRow<FUnitData>(*FString::FromInt(UnitID), TEXT(""));
	

	if (UnitLookupTable != NULL) a = true;

	OutCreatureData = *CreatureLookupTable->FindRow<FCreatureData>(*FString::FromInt(OutUnitData.CreatureDataID), TEXT(""));
	
	if (CreatureLookupTable != NULL) b = true;

	return a && b;
}


Congrats Slayemin. I’m still trying to figure it out via blueprints. I think my CSV is ok

Name,Hex_Type,Location,Difficulty
1,""“Blueprint’/Game/Blueprints/Hex.Hex’”"",0,H
2,""“Blueprint’/Game/Blueprints/Hex.Hex’”"",7,H

Drop one of the “Hex” (And use only one double ), that should do it.

[=;253304]
Drop one of the “Hex” (And use only one double ), that should do it.
[/]

No, this is wrong. My problem was that I was missing the extension and he’s including it correctly.

[]

Congrats Slayemin. I’m still trying to figure it out via blueprints. I think my CSV is ok

Name,Hex_Type,Location,Difficulty
1,“”“Blueprint’/Game/Blueprints/Hex.Hex’”“”,0,H
2,“”“Blueprint’/Game/Blueprints/Hex.Hex’”“”,7,H

[/]

The CSV input looks good to me.

When you say you’re trying to figure it out via blueprints, are you saying that you’re not including source code in your project?

Thing is, BPs are actually a bundle of data. You are not including an extension, you are accessing the object inside of the blueprint. The BP consists (to my knowledge) of the actual Blueprint logic (MyBP.MyBP) and the generated C++ class for the BP (MyBP.MyBP_C). If you want to automatically load up a class from a BP, you’d do it like this:

[]
“UClass’/Game/Blueprints/Spells/BP_Fireball.BP_Fireball_C’”
[/]

In my struct I have

[]
UPROPERTY(BlueprintReadOnly, Category = “Magic”)
TSubclassOf<AActor> SpellClass;
[/]

This works like a charm for me. All my spells derive from a shared base class so I just cast the Actor class I get to my own class and work with that.

I finally figured it out! The problem was that my reference locations were wrong. When I first started working on this I read(?) that you get the actor reference by right clicking on it on the Content Browser and then select Copy Reference (ex. Blueprint’/Game/Blueprints/Hex.Hex’). When I imported the CSV it appeared as None values. I tried all the suggestions in this thread and others but nothing worked so I decided I should go with making a Struct using the Data Table variable type inside the Level Blueprint. With the Struct I was able to specify the actor and I noticed that I can right click and Copy it. I pasted it into notepad and noticed that the reference was different (BlueprintGeneratedClass’/Game/Blueprints/Hex.Hex_C’). What the??! I put pasted it into my CSV (no double quotes), reimported it and it worked!

Hopefully this can help anyone else having difficulty with calling actors in datatables.

Is there currently any way to edit data values from in-game events?

How I Transform FRichCurve variable in UCurveFloat ?

Hi, Before i Transform my line DataTable in FRichCurve how i Tarsnform this object in UCurveFloat to insert in timeline object interpol?

Does anyone know if you can update rows (i.e. add rows) to a FTableRowBase during game play. For example, could I collect various stats, at different timepoints and then place them into a datatable and then save them as a csv for analysis outside of Unreal? Since the time of gameplay the # of rows would be variable depending on the length of time play.

Thanks,

Hmm I just discovered that “Datatable Improvements” which was part of Fortnite-driven items has been dropped… :frowning:
https://trello.com/c/XxJWYAzM/549-fortnite-requested-editor-improvements-removed-overbroad
I wonder what the outlook is now for datatable improvements…:confused:

Just a sidenote: Excel,Libre office etc, generate a .~****lock file that prevents other programs from loading and reading the spreadsheet. That’s why you should not have the sheet open in excel or etc.
And something that needs to be added to documentation: A “Name” column is expected to be the first one.

[]
And something that needs to be added to documentation: A “Name” column is expected to be the first one
[/]

I do remember having read this somewhere in the documentation…

Can this be done without any coding and just with blueprints?

[=;332477]
Can this be done without any coding and just with blueprints?
[/]

Do you mean can you access and utilize data tables/csv files without using code? If so then the answer is yes! It is quite possible to access information from data tables via blueprints.