Error when adding Widget to Viewport with branch

Hi everyone

I was adding one of two WidgetBlueprints to the viewport and I found I was getting an error when placing a branch before choosing which widget to add. If I do the following, then I get no error, just a warning at comile. In the blueprint after, I get an error “Blueprint Runtime Error: “Accessed None trying to read property CallFunc_Create_ReturnValue_1”. Blueprint: Minimal_Default Function: Execute Ubergraph Minimal Default Graph: EventGraph Node: Add to Viewport”.

At one stage I tried checcking if the output from the widget was valid, and that the owning player was valid but that did not help.

The widgets display fine in both. This project is just a blank project in with 2 simple widgets with some text to demonstrate the issue.

Blueprint with error below

So why do I get an error when I have a branch?

Thanks in advance.

Eyo,

I believe Unreals BP system is “optimized” in a way that it is not “smart enough” to figure this out. But, if there where any confusion on why the error pops up is that trying to access the return value from both of the widgets at the same time where one of them is a “nullptr” as it has not been instansiated.

Thanks for helping :slight_smile:

Wouldn’t ‘Is Valid’ check for this? Or could a widget be valid (not null) but not be instantiated? I have tried checking the return values for both widgets using ‘Is Valid’ and get the same error. Unless that gets optimized away?

Yes, I would recommend you do IsValid checks almost anytime you want to access or send a pointer.

The issue with checking both values with IsValid is that you are not checking both values at the same time so it just automatically accesses the “other” null value afterward.

I would probably make a function with an input of a class and keep the IsValid Check after creating it.