What's the correct way to load blueprints for packaging?

Hi,

I am using this routine to load my BP in c++:

static ConstructorHelpers::FObjectFinder<UBlueprint> BP_d4Object(TEXT("Blueprint'/Game/dice/D4_Dice_BP.D4_Dice_BP'"));
BP_d4 = (UClass*)BP_d4Object.Object->GeneratedClass;

Doing this for all my BP derived objects.

It works well when launched from the editor, but when it comes to packaged game i get various and seemingly random results (working well / object not spawning but game going on / game crash).

In all cases, the error seems to be an access violation.

So my question is: am i doing this correctly ?

If no, what is the correct way ?

Is there any option i should use in editor or in my code or in the configuration files ?

I have already set bDontLoadBlueprintOutsideEditor=false in the DefaultEditor.ini (and made a request so it’s set to false by default when creating a project). Anything else ?

Thanks

Cedric

Edit:

The crash was due to the fact that i was trying to reach a non spawned object.

So the only problem is that the blueprints declared this way won’t spawn in packaged game (but this causes no crash).

Ok, anyone reading this, here is how it should be done, copied from here:

It’s true by default because Blueprints are not needed outside the editor.

It looks like you’re attempting to access the Blueprint generated class through the Blueprint itself. Rather, you should just reference the class directly.

For Blueprint’/Game/dice/D4_Dice_BP.D4_Dice_BP’

The class reference is Class’/Game/dice/D4_Dice_BP.D4_Dice_BP_C’

static ConstructorHelpers::FObjectFinder<UClass> bpClassFinder(TEXT("Class'/Game/dice/D4_Dice_BP.D4_Dice_BP_C'"));
 if (bpClassFinder.Object)
 {
     UClass* bpClass = bpClassFinder.Object;
 }
1 Like

When I copy my blueprint reference I get:

Blueprint’/MediaFrameworkUtilities/BP_MediaBundle_Plane_16-9.BP_MediaBundle_Plane_16-9’

I tried loading it like:

static ConstructorHelpers::FObjectFinder mediaBundleFinder(TEXT(“Class’/MediaFrameworkUtilities/BP_MediaBundle_Plane_16-9.BP_MediaBundle_Plane_16-9_C’”));

but I still get an error:

Failed to find Class’/MediaFrameworkUtilities/BP_MediaBundle_Plane_16-9.BP_MediaBundle_Plane_16-9_C’

Note you have to add a _C (which is the class name of the blueprint) at the end of the ref!

Thank you so much for posting this, I’ve been tearing my hair out for hours 10 years later lmao!