Why does setting this variable to false break my toggle inventory?

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.

Once again I solve my own problem.

This involved SetIgnoreLookInput(). Whenever I was opening the inventory it would call SetIgnoreLookInput(true), which added 1 to the bool LookInput inside the controller, it then also would do it when I examined and then closed the examination widget and reopened the inventory making it 2. This is why when closing the inventory after doing an examination of an item would cause my look input to fail. Whenever you call SetIgnoreLookInput(false) (at least in my case) it was just decrementing 1 from the LookInput bool making LookInput 1 and thus making the ignorelookinput still true.
All I did to fix this was to use ResetIgnoreLookInput() right before setting it to true in the function as you can see below and now everything is function fine.

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();
			ResetIgnoreLookInput();
			SetIgnoreLookInput(true);
			bShowMouseCursor = true;
			InventoryMenuWidget->SetVisibility(ESlateVisibility::SelfHitTestInvisible);
			InventoryMenuWidget->CloseDropDownMenu();
			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();
			ResetIgnoreLookInput();
			SetIgnoreLookInput(true);
			InventoryMenuWidget->SetVisibility(ESlateVisibility::SelfHitTestInvisible);
			InventoryMenuWidget->CloseDropDownMenu();
			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);
			}
		}
	}
}