StaticLoadObject doesn't work in a packaged game

Hello all.

I want to create an Actor in C++, and this Actor is defined with Blueprint.

So, I tried this code below.

UClass* Class = NULL;
UObject* uobj = StaticLoadObject(UBlueprint::StaticClass(), NULL,TEXT("Blueprint'/Game/Project/Blueprints/TestCharacter.TestCharacter'"));
if (uobj != NULL) {
	UBlueprint* blueprint = Cast(uobj);
	Class = blueprint->GeneratedClass;
}

FTransform SpawnTransform;
FActorSpawnParameters SpawnParameters;
SpawnParameters.SpawnCollisionHandlingOverride = CollisionHandlingOverride;
AActor* act = GetWorld()->SpawnActor(Class, &SpawnTransform, SpawnParameters);

It works fine when I run this in the UE4Editor.

But in a packaged game, StaticLoadObject() returns NULL.

In addition, I could create this Actor from Blueprint-to-C++ function like this in the same packaged game.

So, I think ‘TestCharacter Actor’ is cooked and included in a game package.

AActor* AMyTest::SpawnActor(UClass* Class, FTransform SpawnTransform, ESpawnActorCollisionHandlingMethod CollisionHandlingOverride)

I’m using UE 4.10.1, and packaged for Windows 64bit.

Could you give me some advices?

Thanks in advance.

Hello Tatsuya-

Blueprints are defaulted to be stripped out when cooking. This can be overridden in the DefaultEditor.ini file by changing “bDontLoadBlueprintOutsideEditor” from true to false. After making this change and packaging again the result in the packaged version should match what is seen in the editor / standalone.

Cheers

Doug Wilson

Hi Doug, I want to say thank you!
It solved my issue.