Widget Blueprints that are only referenced in code are not cooked correctly

Hi all, I recently started using UMG for my project, and have some widgets that are loaded and created from C++, rather than Blueprints. But, for some reason it looks like they won’t load correctly when I try to run my packaged game. But, everything works fine in the editor. I was able to verify that the uassets for these blueprints are being copied correctly after the Cook, and they’re definitely there, so I’m puzzled as to what the issue could be.

Here is an excerpt from the logs when I start seeing these errors:

[2015.01.18-13.54.08:668][  0]LogUObjectGlobals:Warning: Failed to find object 'Blueprint /Game/UI/Nameplate.Nameplate'
[2015.01.18-13.54.08:668][  0]Error: CDO Constructor: Failed to find Blueprint'/Game/UI/Nameplate.Nameplate'
[2015.01.18-13.54.08:669][  0]LogUObjectGlobals:Warning: Failed to find object 'Blueprint /Game/UI/DamageText.DamageText'
[2015.01.18-13.54.08:669][  0]Error: CDO Constructor: Failed to find Blueprint'/Game/UI/DamageText.DamageText'
[2015.01.18-13.54.08:669][  0]LogTemp:Warning: Instansiating medium armor
[2015.01.18-13.54.08:756][  0]LogTemp:Warning: Instansiating medium armor
[2015.01.18-13.54.08:760][  0]LogUObjectGlobals:Warning: Failed to find object 'Blueprint /Game/UI/PreGame/MainMenuUI.MainMenuUI'
[2015.01.18-13.54.08:760][  0]Error: CDO Constructor: Failed to find WidgetBlueprint'/Game/UI/PreGame/MainMenuUI.MainMenuUI'
[2015.01.18-13.54.08:769][  0]LogUObjectGlobals:Warning: Failed to find object 'Blueprint /Game/UI/PreGame/Lobby.Lobby'
[2015.01.18-13.54.08:769][  0]Error: CDO Constructor: Failed to find WidgetBlueprint'/Game/UI/PreGame/Lobby.Lobby'
[2015.01.18-13.54.08:769][  0]LogTemp:Warning: Shield stopped
[2015.01.18-13.54.08:848][  0]LogUObjectBase:Warning: -------------- Default Property warnings and errors:
[2015.01.18-13.54.08:848][  0]LogUObjectBase:Warning: Error: CDO Constructor: Failed to find Blueprint'/Game/UI/Nameplate.Nameplate'
[2015.01.18-13.54.08:848][  0]LogUObjectBase:Warning: Error: CDO Constructor: Failed to find Blueprint'/Game/UI/DamageText.DamageText'
[2015.01.18-13.54.08:848][  0]LogUObjectBase:Warning: Error: CDO Constructor: Failed to find WidgetBlueprint'/Game/UI/PreGame/MainMenuUI.MainMenuUI'
[2015.01.18-13.54.08:848][  0]LogUObjectBase:Warning: Error: CDO Constructor: Failed to find WidgetBlueprint'/Game/UI/PreGame/Lobby.Lobby'

Here’s how I am loading them in C++:

	static ConstructorHelpers::FObjectFinder<UBlueprint> LobbyBlueprintObject(TEXT("WidgetBlueprint'/Game/UI/PreGame/Lobby.Lobby'"));
	if (LobbyBlueprintObject.Object != NULL)
	{
		LobbyWidgetClass = (UClass*)LobbyBlueprintObject.Object->GeneratedClass;
	}

I’ve tried packaging through the editor, with both PAK enabled and disabled, and have also tried packaging using RunUAT and the command below, also with the PAK option enabled and disabled, and every time I seem to fail with the same issue. I have also tried explicitly adding the content directory where these are stored as a -CookDir option, and that didn’t help.

RunUAT BuildCookRun -project="%CD%\Moonstorm.uproject" -Build -noP4 -platform=Win64 -clientconfig=Development -serverconfig=Development -pak -nocompile -cook -maps=AllMaps -stage -archive -CookDir="%CD%\Content\UI" -archivedirectory="%CD%\Out"

Does anyone have any idea what I could be doing wrong here? Thanks!

Not necessarily a solution, but I ended up just creating the widgets from BPs and assigning the UUserWidget pointer in my C++ class. This is not ideal, because it ends up with me either having to create a parent BP for all my BPs, or have a lot of repetition that I could otherwise avoid.

Anybody figure out the reason behind this?

Hello, try using UClass instead of UBlueprint for your FObjectFinder, it worked well for me. You also have to change the path of your blueprint by adding ‘_C’ . for your code that would give this

static ConstructorHelpers::FObjectFinder<UClass> LobbyBlueprintObject(TEXT("/Game/UI/PreGame/Lobby.Lobby_C"));
if (LobbyBlueprintObject.Object != NULL)
{
LobbyWidgetClass = LobbyBlueprintObject.Object;
}

Wow, it’s amazing!

Wow, it’s amazing!
Not sure if this is sarcasm…

Base native classes are derived directly from UUserWidget. Base class is set in blueprints with Graph > Class settings. Works fine in editor, but refuses to package (Class not found errors). Tried casting to UBlueprint and UClass with and without _C suffix.
Anyone else been here and solved this problem (was on 4.7.6, now on 4.8.2).

Doh! - I’m my case I had neglected to explicitly include the blueprints directory so the (unreferenced except in native code) blueprints weren’t being cooked.