Download

how to add blueprint pawn to c++?

I want to create poseable mesh in blueprint, set up the camera and plug it into c ++ and write the logic of the movement in C++. which C++ class I need to choose? and how to pass values to blueprint

Hi,

can you give some more information please? What are you trying todo?

-freakxnet

Spawn a BP pawn in C++?

First, you will need to get the blueprint class. You can do this with FClassFinder like so:



UClass* MyPawnBlueprintClass;

static ConstructorHelpers::FClassFinder<APawn> MyPawnFinder(TEXT("/Game/MyBlueprintPawn"));
if(MyPawnFinder.Class)
  MyPawnBlueprintClass = (UClass*) MyPawnFinder.Class;
else
  UE_LOG(LogTemp, Warning, TEXT("MyBlueprintPawn was not found!"));

I do that stuff in my GameMode constructor. It has to happen that early on or things get wonky, IIRC.
And make sure the path you give the finder matches the path to your blueprint within the Content directory.

Then you can use MyPawnBlueprintClass as a parameter to the SpawnActor() function. Something like this:



APawn* myPawnActor = world->SpawnActor<APawn>(MyPawnBlueprintClass, location, rotation);

(where location and rotation are an FVector and FRotator, respectively)

I would recommend using this instead of getting your class by hard-coded string:



UPROPERTY(EditAnywhere, Category = Whatever)
TSubClassOf<APawn> MyBPClass;




Pawn* myPawnActor = world->SpawnActor<APawn>(MyBPClass, location, rotation);


You should be able to pick your Blueprint class derived from APawn in the editor.

Look at that. I try to help someone and I get a pro-tip. That worked great. Thanks!

I want to create poseable mesh in blueprint, set up the camera and plug it into c ++ and write the logic of the movement in C++. which C++ class I need to choose? and how to pass values to blueprint

I cannot to use this code:
APawn* myPawnActor = world->SpawnActor<APawn>(MyPawnBlueprintClass, location, rotation);
what is the “world”? what class c++ i must to use?Pawn?

Sorry, I assumed that you would have known that. The “world” variable is of type UWorld* and it is retrieved by calling the GetWorld() function. What I and queelaga are describing is usually done within a class derived from AGameWorld. But I don’t think this is what you want to do anyway.

Specific to what you said you are trying to do, I think you want to just start with a C++ template project. If you do that then there will be a C++ character class for you to work with and also a blueprint character that is derived from that C++ class. Since the blueprint character is derived from the C++ class, they already are connected via inheritance. You can use the UPROPERTY() and UFUNCTION() features to allow both sides to ‘communicate’.

Just make sure you use a C++ template project that includes a character, such as the first-person and third-person templates.