충돌이 가능한 Pawn을 생성해 보자
우선 마켓플레이스에서 필요한 컨텐츠를 다운받는 법을 설명하자면
충돌을 위한 Collider Pawn 클래스 생성
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "Collider.generated.h"
UCLASS()
class BASIC_API ACollider : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
ACollider();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
UPROPERTY(VisibleAnywhere, Category = "Mesh")
class UStaticMeshComponent* MeshComponent;
UPROPERTY(VisibleAnywhere, Category = "Mesh")
class USphereComponent* SphereComponent;
FORCEINLINE UStaticMeshComponent* GetMeshComponent() { return MeshComponent; };
FORCEINLINE void SetMeshComponent(UStaticMeshComponent* Mesh) { MeshComponent = Mesh; }
FORCEINLINE USphereComponent* GetSphereComponent() { return SphereComponent; };
FORCEINLINE void SetSphereComponent(USphereComponent* Sphere) { SphereComponent = Sphere; }
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "Collider.h"
#include <Engine/Classes/Components/SphereComponent.h>
// Sets default values
ACollider::ACollider()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComponent"));
SphereComponent->SetupAttachment(GetRootComponent());
SphereComponent->InitSphereRadius(40.0f);
SphereComponent->SetCollisionProfileName(TEXT("Pawn"));
}
// Called when the game starts or when spawned
void ACollider::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ACollider::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void ACollider::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}
Blueprint 생성
Sphere Component의 Simulate Physics를 켜준다.
여기까지하고 Unreal에 적용해도 보이진 않는다.
Mesh 적용
// Fill out your copyright notice in the Description page of Project Settings.
#include "Collider.h"
#include <Engine/Classes/Components/SphereComponent.h>
#include <Engine/Classes/Components/StaticMeshComponent.h>
#include <UObject/ConstructorHelpers.h>
// Sets default values
ACollider::ACollider()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComponent"));
SphereComponent->SetupAttachment(GetRootComponent());
SphereComponent->InitSphereRadius(40.0f);
SphereComponent->SetCollisionProfileName(TEXT("Pawn"));
MeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComponent"));
MeshComponent->SetupAttachment(GetRootComponent());
static ConstructorHelpers::FObjectFinder<UStaticMesh> MeshComponentAsset(TEXT("StaticMesh'/Game/StarterContent/Shapes/Shape_Cone.Shape_Cone'"));
if (MeshComponentAsset.Succeeded())
{
MeshComponent->SetStaticMesh(MeshComponentAsset.Object);
MeshComponent->SetRelativeLocation(FVector(0.f, 0.f, -40.f));
MeshComponent->SetWorldScale3D(FVector(0.8f, 0.8f, 0.8f));
}
}
// Called when the game starts or when spawned
void ACollider::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ACollider::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void ACollider::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}