Using Blueprint created Structure inside C++ code

I have created a blueprint structure (user defined structure). I also have a Blueprint Function Library, which is in c++. I would like to access this structure in that file but I cannot find any way to do so. (I am using the BlueprintFirstPerson project template)

Hello Excutron, I believe the section you’re looking for is “Calling Functions across the C++ and Blueprint” in click here. I hope this helps and good luck!

It would be very hacky not really straightforward to ‘use’ a BP structure in C++, the easiest way is just implement your struct in C++. Just add a new one and expose it to Blueprints, do not use the same name though, and refactor your BP code to use the new struct.

I just came across this problem and I’ve wrote some code.

I didn’t test this but it should work.

    bool MyFunctionThatGetsValFromABPTable(FString TablName, FString TargetRowName, FString PropertyName, T& OutValue)
    	//load your table first
    	UDataTable* DataTablePtr = LoadObject<UDataTable>(nullptr, *TablName);
    	//safty first
    	if (!DataTablePtr)
    		return false;
    	uint8* RowData = DataTablePtr->FindRowUnchecked(TargetRowName);
    	UScriptStruct* pStruct = DataTablePtr->RowStruct;
    	if (!pStruct)
    		return false;
    	for (UProperty* Property = pStruct->PropertyLink; Property != NULL; Property = Property->PropertyLinkNext)
    		FString StaticPropertyName = Property->GetName();
    		if (StaticPropertyName.Contains(PropertyName))
    			return GetVal(RowData, Property, OutValue);
    //get string value
    bool GetVal(uint8* ptr, UProperty* prop, FString& v)
    	if (UStrProperty* p = Cast<UStrProperty>(prop))
    		v = p->GetPropertyValue_InContainer(ptr);
    		return true;
    	return false;
    //you should also write your own overloaded functions to get your float, int etc.
    bool GetVal(uint8* ptr, UProperty* prop, FString& v);
    bool GetVal(uint8* ptr, UProperty* prop, int32& v);
    bool GetVal(uint8* ptr, UProperty* prop, float& v);
    //now call your function in somewhere...
    float maxHealth = 0; 
    FName TargetRowName("001");//id as row name
    FString PropertyName("MaxHealth");// we wanna get the maxmum health of the monster 001 
    FString TablName("/Game/MyMonsterTable.MyMonsterTable");// table refrence 
    MyFunctionThatGetsValFromABPTable(TargetRowName, PropertyName, TablName, maxHealth);
    //now you've reterived the value from your BP table.
1 Like

there 's a doc here : Converting Blueprint to C++ | Course

Thank you for your Answer, It has solve my problems.