question

dylan-1 avatar image
dylan-1 asked

[ue4] How to convert a cpp result struct/model to bp-friendly?

I saw there are both cpp and bp models: However, the average dev uses both. Eg: as a backend dev, I get the data and prep some getters for the frontend to grab it via BP in a minimalist fashion.

Your cpp structs are quite complex, nested deep; and most notably: not friendly to manually recreate as a BP-friendly USTRUCT.

Since it was coded without considering BPs, is it safe to assume there's a tool to convert within the SDK?

Eg (pseudocode): Models::ParseUStructVariant<SomeCppModel>();

Where can I find this?

unreal
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dylan-1 avatar image dylan-1 commented ·

Got a lead, maybe something like this?

const FString ClansJsonStr = MyClan.toJSONString(); // MyClan is the cpp model variant.
FGroupsGetGroupResponse* BPMyClan = NewObject();
FJsonObjectConverter::JsonObjectStringToUStruct(ClansJsonStr, BPMyClan);
0 Likes 0 ·
dylan-1 avatar image
dylan-1 answered
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Rick Chen avatar image
Rick Chen answered

There is no such function in Unreal SDK. You may feel free to create one by yourself.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dylan-1 avatar image dylan-1 commented ·

After attempting to create one, I realized it's very expensive and overly convoluted. The best answer seems to be to overload the USTRUCT constructor to allow a Cpp variant, then copy those vals over.

However, it's a pain since we'd have to edit your lib and feels like something that should already be there. Would you guys consider adding an update to accept a Cpp constructor in your models? I'm surely not the only developer that focuses on backend while another dev focuses on BPs.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.