Cannot Spawn Blueprint from C++

Hi all, so I’ve just started getting into UE4 and have been tinkering around things working on a prototype for a game. I’m far more used to using C++ than working with blueprints. From what I’ve read you can spawn blueprints through C++. I’m currently trying to spawn a blueprint from C++ and using the following method that I’ve found to be the general consensus of how to spawn it through C++.

.h

TSubclassOf<ARock> RockBP;

.cpp

static ConstructorHelpers::FObjectFinder<UBlueprint> RockOb(TEXT("Blueprint'/Game/Blueprints/RockBP.RockBP'"));
if (RockOb.Object)
{
	RockBP = (UClass*)RockOb.Object->GeneratedClass;
}

However, I receive the following error in Visual Studios

I’ve tried searching through the answer hub but have yet to find a solution. Any help is much appreciated!

Hi, I was pretty much stuck like you but solved it with another ConstructorHelpers Function.

		static ConstructorHelpers::FClassFinder<AResources> ThisResource(TEXT("/Game/Blueprints/MyTest"));
		if (ThisResource.Class != NULL)
		{
			UClass* WarriorBP = ThisResource.Class;
			AResources* NewCreature = World->SpawnActor<AResources>(WarriorBP, SpawnLocation, SpawnRotation, SpawnParams);
		}

I hope this helps

Hey, I have the same problem, you said you are new to UE4 so first you must know there are problems with spawning blueprints in code in 4.6 version, it was working fine in previous versions. It is explained in the 4.6 Release notes :
Unreal Engine 4.6 Released! - Announcements - Unreal Engine Forums!
I quote:

“More changes are planned for GENERATED_BODY with the 4.7 release and users with existing code may wish to delay switching existing classes until then.”

You now define and use “normal” C++ constructors for your classes. You can use parameterless constructors too now!

You no longer need to supply a category for your properties to expose them to the editor or Blueprints. You’ll get a default category now.

FPostContructInitializeProperties is deprecated. It’s replaced by FObjectInitializer, and you only have to specify it when you actually need it

“GENERATED_BODY” no longer resets your protection level to “public”. It will preserve your settings.

Please use the new “GENERATED_BODY” specifier instead of “GENERATED_UCLASS_BODY”. It enables many of these new improvements!

I have been trying to make this work in all sort of ways including the FClassFinder suggestion below , but either it didn’t compile or something goes wrong when running the game.
I posted a question last week:

Anyway, if you add #include “Engine.h” at start of your .cpp that error on your screenshot will go away and you can compile, it will not fix the problem thou,
I tried that already :P.