Runner Ue4.26 C++ 개발하기 #4

박기덕·2021년 3월 26일
0

UE4 C++ Runner Project

목록 보기
4/5

Actor

1.헤더 파일 Actor 에서 사용할 컴퍼넌트 설정

UPROPERTY(VisibleAnywhere,BlueprintReadOnly,Category="Components")
USceneComponent* SceneComponent;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
UStaticMeshComponent* FloorMesh;

2.CPP 파일

SceneComponent = CreateDefaultSubobject(TEXT("Scene"));
RootComponent = SceneComponent;

FloorMesh = CreateDefaultSubobject(TEXT("FloorMesh"));
FloorMesh->SetupAttachment(SceneComponent);

3.Widget 처럼 빌드 후에 에디터에서 컴퍼넌트 설정한다.
4.Random 과 생성 , InRange , Spawn 관련
const float RandVal = FMath::FRandRange(0.f, 1.f);
FActorSpawnParameters SpawnParameters;
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;

const FTransform& SpawnLocation = Lane->GetComponentTransform();

if (UKismetMathLibrary::InRange_FloatFloat(RandVal , SpawnPercent1 , SpawnPercent2 , true , true))
{
	AObstacle* obstacle = GetWorld()->SpawnActor<AObstacle>(SmallObstacleClass, SpawnLocation, SpawnParameters);
}

5.GameModeBase 관련 begin play 에서 설정해놓는다.
RunnerGameMode = Cast(UGameplayStatics::GetGameMode(GetWorld()));

6.충돌
FloorTriggerBox->OnComponentBeginOverlap.AddDynamic(this, &AFloorTile::onTriggerBoxOverlap);
onTriggerBoxOverlap 파라미터를 알아내려면

VS 에서 OnComponentBeginOverlap f12 누르면
FComponentBeginOverlapSignature OnComponentBeginOverlap;
가 나온다.
FComponentBeginOverlapSignature f12 누르면
DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_SixParams( FComponentBeginOverlapSignature, UPrimitiveComponent, OnComponentBeginOverlap, UPrimitiveComponent, OverlappedComponent, AActor, OtherActor, UPrimitiveComponent*, OtherComp, int32, OtherBodyIndex, bool, bFromSweep, const FHitResult &, SweepResult);

위를 참고 하여 파라미터 설정 ( 뒤에서 부터 , 를 지운다. )
FComponentBeginOverlapSignature, UPrimitiveComponent, OnComponentBeginOverlap 는 삭제

onTriggerBoxOverlap(UPrimitiveComponent OverlappedComponent, AActor OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)

  1. 타이머
    헤더에 선언
    UPROPERTY()
    FTimerHandle DestroyHandle;

cpp 에서 생성
GetWorldTimerManager().SetTimer(DestroyHandle, this, &AFloorTile::DestroyFloorTile, 2.0f , false );

cpp 에서 삭제
if (DestroyHandle.IsValid())
{
GetWorldTimerManager().ClearTimer(DestroyHandle);
}

  1. TARRAY
    TArray<AFloorTile*> FloorTiles;

    FloorTiles.Empty();
    FloorTiles.Add(Tile);
    FloorTiles.Remove(Tile); //내부에서 find 해서 지운다.

profile
언리얼 개발자

0개의 댓글

관련 채용 정보