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++. What class(pawn/actor/scene component/blueprint function library) should I use to connect blueprint poseable mesh in c ++? how to pass values to blueprint?please give me a simple code samples, step by step. thanks
Have you tried watching the C++ programming tutorial in the Unreal Engine videos tutorials section? All the answers to your questions had been already answered in this tutorial.
To answer your question, You should create a new C++ class and select your desired parent class to inherit from.
It seems that you would want a Character parent class. The following example code sets up FollowCamera and CameraBoom object and attaches them to the back of the Character. change the values as you wish:
TestCharacter.h
#pragma once
#include "GameFramework/Character.h"
#include "TestCharacter.generated.h"
UCLASS()
class DESTINTAIONUNKNOWN_API ATestCharacter : public ACharacter
{
GENERATED_BODY()
/** Camera boom */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class USpringArmComponent* CameraBoom;
/** Follow camera */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class UCameraComponent* FollowCamera;
public:
// Sets default values for this character's properties
ATestCharacter();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
};
TestCharacter.cpp
#include "TestProject.h"
#include "TestCharacter.h"
// Sets default values
ATestCharacter::ATestCharacter()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
/** Set capsule size for collision */
GetCapsuleComponent()->InitCapsuleSize(20.0f, 20.0f);
/** Create camera boom */
CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
CameraBoom->SetupAttachment(RootComponent);
CameraBoom->TargetArmLength = 100.0f;
/** Create Follow camera and bind to camera boom */
FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
FollowCamera->bUsePawnControlRotation = true;
}
// Called when the game starts or when spawned
void AStarshipCharacter::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AStarshipCharacter::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
Hi,
extend your C++ class from ACharacter. Reparent your blueprint to this C++ class. Add UPROPERTIES / UFUNCTIONS to your C++ class. Route variables from / to Blueprints and C++.