Hi, everybody. I have a UUserWidget class InventoryWidget
I need placed in variable
TSubclassOf<class UInventoryCell> InventoryCellClass
a link to the “Widget Bluprint”, when creating a widget InventoryWidget
And when calling
AddInventoryCell
the widget UInventoryCell class was created and placed in UUnoformGridPanel in “InventoryWidget”
InventoryWidget.h
#include "Blueprint/UserWidget.h"
#include "Components/UniformGridPanel.h"
#include "../../../InventoryCell.h"
public:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
class UUniformGridPanel* InventoryCells;
protected:
virtual void NativeConstruct() override;
private:
UPROPERTY(EditDefaultsOnly)
TSubclassOf<class UInventoryCell> InventoryCellClass;
UFUNCTION(BlueprintCallable)
void AddInventoryCell(float SizeY, float SizeX, int32 PossitionY, int32 PossitionX);
InventoryWidget.cpp
void UInventoryWidget::NativeConstruct()
{
Super::NativeConstruct();
FStringClassReference InventoryCellClassRef(TEXT("/Game/TestInventoryCell"));
InventoryCellClass = InventoryCellClassRef.TryLoadClass<UInventoryCell>();
}
void UInventoryWidget::AddInventoryCell(float SizeY, float SizeX, int32 PossitionY, int32 PossitionX)
{
UInventoryCell* NewInventoryCell = CreateWidget<UInventoryCell>(this, InventoryCellClass);
InventoryCells->AddChild(NewInventoryCell);
NewInventoryCell->CreateInventoryCell(SizeY, SizeX, PossitionY, PossitionX);
}
InventoryCell.h
UFUNCTION(BlueprintCallable)
void CreateInventoryCell(float SizeY, float SizeX, int32 StartPossitionY, int32 StartPossitionX);
Server logged in
CreateWidget called with a null class.
Play in editor total start time 0,133 seconds.
Error at startup: