Hi,
I have a bit of a best practise question about how to best call a widget to show. Basically, I have an inventory widget that I wont to show when an input action occurs (i.e. the player presses i). When this happens I want to pass an array of items to the widget blueprint in order to render it as the inventory.
However, I am not sure how best to actually go from the input action to the widget, I figured I should be using either my playercontroller class of my HUD class. At the moment I simply have the inventory widget blueprint as a member in the player controller and basically just call show() like so:
void AOPlayerController::Possess(APawn* InPawn)
{
Super::Possess(InPawn);
if (InventoryWidgetType)
{
//Create the Inventory Widget based on the Blueprint reference we will input from within the Editor
InventoryWidget = CreateWidget<UOInventoryWidget>(this, InventoryWidgetType);
}
//Initial value
bIsInventoryOpen = false;
}
void AOPlayerController::HandleInventoryInput(UOInventory* Inventory)
{
if (InventoryWidget)
{
if (bIsInventoryOpen)
{
// Set the flag to false as the inventory was open and is about to be closed
bIsInventoryOpen = false;
//Remove it from the viewport
InventoryWidget->RemoveFromViewport();
}
else
{
// Set the flag to true as we are opening the inventory
bIsInventoryOpen = true;
//Re-populate the ItemsArray
InventoryWidget->InventoryItems = Inventory->GetInventoryItems();
//Show the inventory
InventoryWidget->Show();
}
}
}
However, I feel like I should be using my HUD class as all the widget examples I have seen use the HUD to store the widget object and to call show. So my question is basically should I be using my HUD class to store the inventory widget and to call show? and if that is the case do I still go via the playercontroller? (i.e. call the player controller which inturn does something in the HUD)