본문 바로가기
Unreal Engine4 or 5/코드

UE4 C++코드로 디폴트에 Mesh 불러오는법

by 눈야옹 2016. 5. 4.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
AStageFloor::AStageFloor()
{
     // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;
 
    RootComp = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
    RootComp->SetWorldLocation(FVector(0.0f, 0.0f, 0.0f));
    RootCompScale = FVector(10.0f, 10.0f, 1.0f);
    RootComp->SetWorldScale3D(RootCompScale);
    RootComp->ComponentTags.Add("StageFloor");
 
    RootComponent = RootComp;
 
    FloorMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Floor Mesh"));
    FloorMesh->AttachTo(RootComponent);
//경로를 넣어준다.
    static ConstructorHelpers::FObjectFinder<UStaticMesh> CubeMeshAsset(TEXT("/Game/StarterContent/Shapes/Shape_Cube"));
//경로상에 에셋이 존재해서 성공할경우 작업을 해준다.
    if (CubeMeshAsset.Succeeded())
    {
        FloorMesh->SetStaticMesh(CubeMeshAsset.Object);
        FloorMesh->SetRelativeLocation(FVector(0.0f, 0.0f, -50.0f));
        FloorMesh->SetRelativeScale3D(FVector(1.0f, 1.0f, 1.0f));
    }
 
    static ConstructorHelpers::FObjectFinder<UMaterial> CubeMaterialAsset(TEXT("/Game/Floor/StageFloor_Mtl"));
    if (CubeMaterialAsset.Succeeded())
    {
        FloorMesh->SetMaterial(0, CubeMaterialAsset.Object);
    }
 
    FloorCollision = CreateDefaultSubobject<UBoxComponent>(TEXT("Floor BoxCollision"));
    FloorCollision->AttachTo(RootComponent);
    FloorCollision->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
    FloorCollision->SetRelativeScale3D(FVector(1.5f, 1.5f, 2.0f));
    FloorCollision->ComponentTags.Add("StageFloorBoundBox");
}
 
cs