void AAvatar::ToggleInventory() { APlayerController* PController = GetWorld()->GetFirstPlayerController(); AMyHUD* hud = Cast<AMyHUD>( PController->GetHUD() ); // If inventory is displayed, undisplay it. if( inventoryShowing ) { hud->clearWidgets(); inventoryShowing = false; PController->bShowMouseCursor = false; return; } // Otherwise, display the player's inventory inventoryShowing = true; PController->bShowMouseCursor = true; for( TMap<FString,int>::TIterator it = Backpack.CreateIterator(); it; ++it ) { // Combine string name of the item, with qty eg Cow x 5 FString fs = it->Key + FString::Printf( TEXT(" x %d"), it->Value ); UTexture2D* tex = NULL; if( Icons.Find( it->Key ) ) { tex = Icons[it->Key]; Widget w( Icon( fs, tex ), Classes[it->Key] ); w.bpSpell = Spells[it->Key]; hud->addWidget( w ); } } }