How to trigger a widget in a C++ file

I have an interaction function created in a C++ class and currently, when there’s nothing to interact with, it prints to the output log saying “nothing to interact with.” I’d like to have this appear on the UI I created for the player. I don’t want to create a gui using C++, I just want to call a specific one to appear inside of a C++ function. All the documentation and tutorials I found only show how to create an entire user interface using code. I’ve been finding it very difficult to find tutorials on how to mix blueprints and C++.

Thanks in advance!

Edit: I’ve searched through a lot of documentation and I think I need to use a CreateWidget constructor but I’m not sure how.

There are a few options:

// Directly via the engine
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Message"));

or 

// Via PlayerController. Many different ways to do this. You should check for null references before using
PlayerController* pc = GetWorld()->GetFirstLocalPlayerFromController()->GetPlayerController();

// You should check for null references before using
pc->ClientMessage(TEXT("Message"));

Blueprints are C++ objects as well. I’m sure many will disagree, but I really use Blueprints only for customising member instance data. E.g. a very simple example would be a character that wears a hat. Implement the character logic & data containers (like the hat mesh) in C++ by extending the Character class, then create different BP classes that extends your C++ character class and assign different hats as required.

Edit:

In that case you need a reference to it, e.g.

in your header:

UPROPERTY(EditAnywhere, BlueprintReadWrite,
TSubclassOf<UUserWidget> YourHudWidgetClass;

UPROPERTY()
UUserWidget* YourHudWidget;

Assign your widget to YourHudWidgetClass in the blueprint then and somewhere in your source file:

YourHudWidget = CreateWidget<UUserWidget>(GetWorld(), YourHudWidgetClass);
YourHudWidget->AddToViewport();

But these seem like ways to just make text appear. I’ve already created the widget blueprint and the animation to fade it in and out. All I need to do it add and remove it from the viewport at a specific time.

You should probably mention UMG or Widgets in your question if that’s what you’re working with. UI can be anything. In any case, updated my answer.

i think this video will be helpfull. How to Spawn/Create Widget in Unreal Engine C++ - YouTube