4.19.2 - Ensure condition failed: Menu != nullptr

Hey guys in 4.19.2 everything compiles fine but I am now getting a nullptr when calling

UMenuWidget* Menu = CreateWidget<UMenuWidget>(this, InGameMenuClass);

This is sort of frustrating as I have no clue as to what could be causing this right now… Maybe I am just blind but been trying to figure it out the past 2 hours but no luck. Everything is setup the way it should be. The BP is there. I am going to clone the repo now and try with that as well…

The MainMenu is still fine btw, just the in game one that does not want to work…

EDIT:: So after importing a fresh copy of the project from git with the current lecture tree checkout things seem to behave again… I have literally no idea what happened as the code is literally the same…

I had the same issue and for me it turned out to be the path in this line:

ConstructorHelpers::FClassFinder<UUserWidget> InGameMenuBPClass(TEXT("/Game/MenuSystem/WBP_InGameMenu"));

Specifically, the path passed in to the constructor has to match the path to your InGameMenu widget blueprint, in this case /Game/MenuSystem/WBP_InGameMenu. If the path is wrong, I believe the object still gets created but the .Class member will be invalid, hence why you get nullptr when trying to create the widget.

1 Like

I’m having this issue and none of the previous answers have helped.
You can find my code on github here: https://github.com/Alex40144/Unreal-Menu-System

Thanks

Maybe the constructor cached the wrong values. Have you tried restarting the editor?

yep, restarted editor and pc in between trying

Can you confirm that InGameMenuBPClass is null?

yeah, the InGameMenuBPClass is returning null
specifically the second line here is failing:

	UMenuWidget* IGMenu = CreateWidget<UMenuWidget>(this, InGameMenuClass);
	if (!ensure(IGMenu != nullptr)) return;

I fixed it, forgot to set the parent class for the BP in the WBP Blueprint class settings. A small fail moment for me lol

3 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms