How to add an existing blueprint widget to a custom C++ player controller class

Experts,

  I am working on a new unreal project extended out of Collab viewer template. By default this template uses blueprint scripting for the game mode, player controller and game instance. Also, when you are in the game mode, it displays the desktop_UI blueprint widget that has the below 5 buttons 

I am trying to write a C++ code for my custom gamemode, player controller and actor classes. In my player controller class, I want to call this blueprint widget so that when I set the Unreal project settings to my gamemode and player controller classes, this widget shows up in the game mode.

Any help on the C++ code to achieve the above will be appreciated.

you can’t. C++ and BP can talk with each other to some extent. There are some ways about finding functions from name and input output arguments but they are not scalable.

So, create your widget in C++, use UPROPERTY bind widget for widget components, do root insertions and use that class to create child blueprints.

That “bind widget” tag will allow you synchronize your BP and C++ components. So, you can call them from other c++ classes but you can design your style in blueprints.

On the other hand, why C++ for your all game mechanics ?

Do you really use game thread that much ? Did you look at profiler or at least stat unit times ? I use C++ only for ThirdParty library integrations, some async stuffs, low level stuffs.

and my workflow is creating a plugin for specific tasks and using it in blueprints. So, my mechanics can be modular and I can use them in every projects of mine.