Announcement

Collapse
No announcement yet.

Is it possible to "cast" a UDataTable?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Is it possible to "cast" a UDataTable?

    I'm storing each of my cutscenes in a specific struct I made to be imported from a CSV:

    Code:
    USTRUCT(Blueprintable)
    struct FCutsceneDataRow : public FTableRowBase {
    	GENERATED_BODY()
    
    		UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Speech")
    		FString line;
    
    		UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Speech")
    		FName speaker;
    };
    In order to store and access these datatables, I created a second struct that's just an ID,DataTable pair that I can set within the editor:
    Code:
    USTRUCT(Blueprintable)
    struct FCutsceneReference {
    	GENERATED_BODY()
    
    		UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Cutscene")
    		FName ID;
    
    	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Cutscene")
    		UDataTable* cutsceneData;
    };
    
    UPROPERTY(EditAnywhere, BlueprintReadWrite)
    TArray<FCutsceneReference> cutsceneList;

    That all works exactly as it's supposed to. Where I'm starting to have problems is when it comes to getting that data into Blueprint. I made a BlueprintCallable function that takes a key, and returns the value:

    Code:
    UDataTable* UDatabaseManager::GetCutsceneDataTable(FName cutsceneID) {
    
    	for (int i = 0; i < cutsceneList.Num(); i++) {
    		if (cutsceneList[i].ID == cutsceneID) {
    			return cutsceneList[i].cutsceneData;
    			break;
    		}
    	}
    	return nullptr;
    }
    The problem is, this returns a generic UDataTable, not an array of FCutsceneDataRow. That means that I can't use GetDataTableRow, because it doesn't know what kind of data to check for:

    Click image for larger version

Name:	DataTableExample.png
Views:	1
Size:	87.9 KB
ID:	1185268

    I can't connect the data table's pin to a Cast node, which makes me assume that I can't just cast my UDataTable* like I could a class, is there an intended workflow I'm missing to "jump" from generic data table to specific format?
Working...
X