I am trying to generate a computer screen using UMG, basically rendering a UMG widget on a 3D object. I know this question asked quite a bit around but the answers are not detailed enough to provide a full implementation.
Here is what I tried:
I created a Widget Blueprint in UMG with some basic text.
In C++, I get this widget blueprint with the following code:
if (UClass* TestWidgetClass = TestWidgetClassRef.TryLoadClass())
UUserWidget* WidgetUI = CreateWidget(GetWorld(), TestWidgetClass);
Then, I created a UWidgetComponent and set the UUserWidget using SetWidget function:
UWidgetComponent* WCUI = CreateDefaultSubobject(“WC_Test”);
Finally, I try to get the material instance or render target variables of UWidgetComponent but both are NULL, and material count also shows 0 along with WidgetClass not set to anything.
What am I missing here?
The MID isn’t created until it’s needed, you would need to wait until after the first tick, which is when it attempts to initialize all those things. Why do you want access to them, because they were not really intended to be accessed directly.
I will try not to bore you with details but I am trying to implement a functional display of an aircraft where you can see data related to engine, fuel, attitude, navigation etc.
This MFD device is located in front of the pilot inside cockpit, so I have to render it to the vehicle mesh I have created. I also need to blend UMG render target with a camera feed, so that pilot can see the camera feed inside this device with related data.
Should I take a different approach under this condition?
I tried getting the material instance after first tick in my vehicle class but it is set to default checkered pattern material. RenderTarget2D variable of WidgetComponent is also set to null still.
I think the problem occurs from WidgetClass not being set properly. When I set the widget using SetWidget function, UWidgetComponent::Widget variable is set, but in InitWidget function, it reverts back to nullptr since WidgetClass is not set to anything. Should I post a bug report regarding this?
Was this ever figured out?