You can do all of this from your custom player controller class.
You need a reference on the widget blueprint created in the editor. From this reference, you will be able to get the UMG widgets contained inside the blueprint and then bind them/disable them.
In your player controller header file you need:
// Your main widget blueprint reference. Set the reference from your player controller blueprint created from the c++ class
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TSubclassOf<class UUserWidget> WidgetBP;
// The widget itself once instantiated
UPROPERTY()
UUserWidget *MainWidget;
In your player controller cpp file you need: (In BeginPlay)
// Setup input
bShowMouseCursor = true;
UWidgetBlueprintLibrary::SetInputMode_GameAndUI(this);
// Add an instance of your widget blueprint in the world
MainWidget = CreateWidget<UUserWidget>(this, CM_Widget);
if (MainWidget)
MainWidget->AddToViewport();
Then whenever you want to access a widget, just use MainWidget->GetWidgetFromName(“YourWidgetName”) and cast the resulting UWidget* into a UButton* or any other widget you need to access.
Now to bind your UButton *, you need to create a delegate. Basically, it looks like this:
UWidget *Widget = MainWidget->GetWidgetFromName("YourWidgetName");
if (Widget)
{
UButton *YourButton= static_cast<UButton*>(Widget);
FScriptDelegate Del;
Del.BindUFunction(this, "YourDelegateFunctionName");
YourButton->OnClicked.Clear();
YourButton->OnClicked.Add(Del);
}
Last thing you need to know is that your delegate function need to be a (public? BlueprintCallable? Not sure) UFUNCTION to be triggered and obviously need to meet the signature for the trigger event to be called (void YourFunction() for a button onclick event)
And finally, to disable your buttons when camera are switching:
First get your cameras using UGameplayStatics::GetAllActorsOfClass(GetWorld(), ACameraActor::StaticClass(), OutputActorsArray); and then set the current one using SetViewTargetWithBlend(YourCamera) in your player controller.
Then in your OnClicked delegate function, set YourButton->SetIsActive(false) then set a timer which will call a function after the blend time has expire to set YourButton->SetIsActive(true)