Cratewidgets crash in a UUniformGridPanel

I used the CreateWidget in the UUniformGridPanel to create the backpack lattice, and there was no problem with compiling and playing and packaging.But when I click on the blueprint in the editor, it will crash. Is this a BUG?

Hello,

I suspect the Garbage Collector collected your pointers since the are not marked as UPROPERTY()
You can read more here: A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums

I would recommend changing FItemBagInformation to this:

USTRUCT()
struct FItemBagInformation
{
    GENERATED_BODY()

    UPROPERTY()
    class UUniformGridSlot* GridSlot;

    UPROPERTY()
    class UInventoryUserWidget* InventoryUserWidget;

    // .... Continue your implementation here
};

Note you need USTRUCT() and GENERATED_BODY() to be able to use the UPROPERTY() specifiers.

~ Dennis “MazyModz” Andersson

Thank you for your answer, I added macros according to your method, But still will crash。And the error is the same

Hmm that is very strange.

What I would suggest is to use UWidget::Slot property instead of FBagInformation::GridSlot.
Since the Slot property is automatically set when you call UUniformGridPanel::AddChildToUniformGrid

So I would recommend you change to this in your ItemBagUserWidget.cpp [Line: 32]:

BagUniformGridPanel->AddChildToUniformGrid(ItemBagInformation[ArrayIndex].InventoryUserWidget);

UUniformGridSlot* GridSlot = Cast<UUniformGridSlot>(Slot);
GridSlot->SetRow(ItemRow);
GridSlot->SetColumn(ItemColumn);

// ....

So Instead of using ItemBagInformation[Idx].GridSlot you can use

UUniformGridSlot* GridSlot = Cast<UUniformGridSlot>(Slot);

Let me know if that works.

~Dennis

Hello, I tried again, this method does create a grid, but it still crashes when open the UserWidget.

he problem is likely to occur in line 29 CreateWidget Function

When I open the editor control, it will be automatically executes the Initialize() function。

Debugging to line 31, I found my InventoryUserWidget empty.

Therefore, createwidgets should not be created in Initialize().