오브젝트 풀링

jelly·2025년 3월 7일

🔹 오브젝트 풀링 개념
오브젝트 풀링은 반복적으로 생성 및 제거되는 객체(예: 총알, 적 캐릭터 등)를 미리 생성해두고 재사용하는 기법이다. 언리얼 엔진에서는 TArray 또는 TQueue를 사용하여 풀을 관리하고, 필요할 때 가져와서 사용한 후 다시 반환하는 방식으로 구현할 수 있다.

✅ 예제 코드: 총알 오브젝트 풀링 시스템
아래 코드는 총알을 오브젝트 풀링 방식으로 관리하는 예제이다.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Projectile.generated.h"

UCLASS()
class YOURGAME_API AProjectile : public AActor
{
    GENERATED_BODY()
    
public:    
    AProjectile();

    void Fire(const FVector& StartLocation, const FVector& Direction);

    void ResetProjectile(); // 재사용을 위해 상태 초기화

protected:
    virtual void BeginPlay() override;

private:
    UFUNCTION()
    void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, 
               UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
};
profile
jelly

0개의 댓글