How can I get BP class for c++?

How can I set a BP class from my Content Browser into a variable in a c++ class? The class is for spawning an actor.
Can anybody help me?

right click on a actor in your content browser then click on “Copy Reference” (It will copy its path)

in the class.h

TSubclassOf<class AClass> ActorToSpawn

Class.cpp

#include "Engine.h"
#include "Engine/Blueprint.h"

static constructorHelpers::FObjectFinder<UBlueprint> type a name for your variable here( Text("past that path here"));

if (yourVariable.Succeeded())
{
  ActorToSpawn= (UClass*)yourVariable.Object->GeneratedClass;
}

Text? → Error

sorry

TEXT

Hi

I don’t think that the code I gave you is responsible for this crash.

will not it crash if you remove the code I gave you?

Ok, compiling works, but then i have an crash by playing

Sorry, but when I play, and stop it, my edit will crash. When I commit all of your code out, every thing works, but with the line “static ConstructorHelpers::FObjectFinder test (TEXT(“Blueprint’/Game/Test.Test’”));” the crash http://pastebin.com/02rRADUp comes by stopping playing.

The code given by saeedc cannot be used outside of class’s constructor. That’s exactly what the error says:

FObjectFinders can’t be used outside of constructors to find Blueprint’/Game/Test.Test’

I find it more convenient to expose variables like these to editor and assign them there. You still have access to it in code, but setting it up is way more flexible and user friendly. Also, it doesn’t require to recompile the project each time you want to change such variable.

Thank you!

constructorHelpers should be with a capital C :wink: