Unreal Engine

SoundCue를 이용한 램덤 사운드 재생

아이언하트 2024. 1. 29. 10:35

랜덤 사운드를 재생할 사운드웨이브 파일중 하나를 선택해서 SoundCue를 생성해 줍니다.

 

생성된 사운드큐 파일을 더블클릭하여 에디터를 열고  나머지 추가할 사운드 파일들을 선택해서 열려있는 사운드큐 에디터로 드래그앤 드랍 해서 넣어 줍니다.

 

추가가 완료되면 추가된 사운드에셋들을 Random 노드에 연결해 주고 Random노드의 output핀을 Output 노드에 연결해 줍니다.

 

아래의 예제는 발사 버튼을 눌렀을 경우 SoundCue를 재생해서 랜덤 사운드가 출력되도록 하고 있습니다.

UCLASS()
class AShooterPlayerCharacter : public AShooterCharacter
{
	...

protected:
	...

	/** Called when the Fire Button is pressed */
	void FireWeapon();

private:
	...

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Combat, meta = (AllowPrivateAccess = "true"))
	TObjectPtr<USoundCue> FireSound;

};

 

void AShooterPlayerCharacter::FireWeapon()
{
	if (::IsValid(FireSound))
	{
		UGameplayStatics::PlaySound2D(this, FireSound);
	}
}

 

 

캐릭터의 블루프린트 클래스를 열어서 C++에서 추가해준 FireSound 프로퍼티에 앞서 작업한 SoundCue를 연결해 줍니다.

 

'Unreal Engine' 카테고리의 다른 글

Skeletal Mesh 위치, 방향 맞추기  (0) 2024.01.29