So I have this function
void AHG_PlayerController::ToggleInventory()
{
UE_LOG(LogTemp, Warning, TEXT("UsingController: %d"), bIsUsingController);
if (!bIsUsingController)
{
if (InventoryMenuWidget->SelectedSlotWidget)
{
InventoryMenuWidget->SelectedSlotWidget->SlotButton->SetStyle(InventoryMenuWidget->SlotNormalStyle);
}
if (!bIsInventoryOpen)
{
UE_LOG(LogTemp, Warning, TEXT("Open Inventory through Keyboard!"));
bIsInventoryOpen = true;
GetCharacter()->GetCharacterMovement()->DisableMovement();
SetIgnoreLookInput(true);
bShowMouseCursor = true;
InventoryMenuWidget->SetVisibility(ESlateVisibility::SelfHitTestInvisible);
FInputModeGameAndUI InputMode;
InputMode.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock);
InputMode.SetWidgetToFocus(InventoryMenuWidget->TakeWidget());
if (ExaminationWidget->IsInViewport())
{
UE_LOG(LogTemp, Warning, TEXT("ExaminationWidget was in Viewport"));
ExaminationWidget->RemoveFromParent();
SetInputMode(InputMode);
}
else
{
UE_LOG(LogTemp, Warning, TEXT("ExaminationWidget was not in Viewport"));
SetInputMode(InputMode);
}
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Close Inventory through Keyboard!"));
bIsInventoryOpen = false;
GetCharacter()->GetCharacterMovement()->SetMovementMode(EMovementMode::MOVE_Walking);
SetIgnoreLookInput(false);
bShowMouseCursor = false;
InventoryMenuWidget->SetVisibility(ESlateVisibility::Collapsed);
FInputModeGameOnly InputMode;
if (ExaminationWidget->IsInViewport())
{
UE_LOG(LogTemp, Warning, TEXT("ExaminationWidget was in Viewport"));
ExaminationWidget->RemoveFromParent();
SetInputMode(InputMode);
}
else
{
UE_LOG(LogTemp, Warning, TEXT("ExaminationWidget was not in Viewport"));
SetInputMode(InputMode);
}
if (bIsCrouching)
{
SwapInputContext(CrouchContext);
}
else
{
SwapInputContext(StandingContext);
}
}
}
else
{
InventoryMenuWidget->SelectInventorySlot(InventoryMenuWidget->CurrentSelectedSlotIndex);
SwapInputContext(ControllerInventoryMenuContext);
if (!bIsInventoryOpen)
{
UE_LOG(LogTemp, Warning, TEXT("Open Inventory through Gamepad!"));
bIsInventoryOpen = true;
GetCharacter()->GetCharacterMovement()->DisableMovement();
SetIgnoreLookInput(true);
InventoryMenuWidget->SetVisibility(ESlateVisibility::SelfHitTestInvisible);
FInputModeGameAndUI InputMode;
InputMode.SetLockMouseToViewportBehavior(EMouseLockMode::LockAlways);
InputMode.SetWidgetToFocus(InventoryMenuWidget->TakeWidget());
if (ExaminationWidget->IsInViewport())
{
ExaminationWidget->RemoveFromParent();
SetInputMode(InputMode);
}
else
{
SetInputMode(InputMode);
}
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Close Inventory through Gamepad!"));
bIsInventoryOpen = false;
GetCharacter()->GetCharacterMovement()->SetMovementMode(EMovementMode::MOVE_Walking);
SetIgnoreLookInput(false);
InventoryMenuWidget->SetVisibility(ESlateVisibility::Collapsed);
FInputModeGameOnly InputMode;
if (ExaminationWidget->IsInViewport())
{
ExaminationWidget->RemoveFromParent();
SetInputMode(InputMode);
}
else
{
SetInputMode(InputMode);
}
if (bIsCrouching)
{
SwapInputContext(ControllerCrouchContext);
}
else
{
SwapInputContext(ControllerStandingContext);
}
}
}
}
And using it normally nothing breaks and works fine.
I have set up a delegate call for my examine item functionality to close the examine widget and come back to the menu. The problem is, when the widget is created and I toggle the bool
void UInventorySystem::CreateExaminationWidget(int ItemIndex)
{
ExaminationWidget->UpdateWidget(ItemIndex);
InventoryMenuWidget->SetVisibility(ESlateVisibility::Collapsed);
ExaminationWidget->AddToViewport(2);
PlayerController->bIsInventoryOpen = false;
}
And then proceed to close the examination widget and return to the inventory widget (this works fine) but then close the inventory widget, all functions are working except being able to move the mouse to look around. If I don’t set that variable in the CreateExaminationWidget(int ItemIndex) function everything works fine, but then when you close the ExaminationWidget it just returns you to the game.
Any help would be appreciated as I am at a loss as to why setting the variable there would cause the ToggleInventory function to break and have been debugging for hours.