AI Perception BP
AI의 시각, 청각, 데미지 감각 시스템을 블루프린트로 구현합니다
AI Perception 시스템 개요
감각 기반 AI 인식의 구조와 핵심 컴포넌트
AI Perception은 AI에게 환경을 "감각"할 수 있는 능력을 제공합니다. 시각(Sight), 청각(Hearing), 데미지(Damage) 등의 감각으로 주변 Actor를 감지합니다.
// 감지하는 쪽 (AI)
AIPerceptionComponent // AIController에 추가
├─ Sense Config: AI Sight
├─ Sense Config: AI Hearing
├─ Sense Config: AI Damage
└─ Event: OnTargetPerceptionUpdated
// 감지되는 쪽 (Player, NPC)
AIPerceptionStimuliSourceComponent // Pawn에 추가
└─ Register as Source for Senses
├─ AI Sight
├─ AI Hearing
└─ AI Damage
| 감각 | 감지 대상 | 주요 설정 |
|---|---|---|
| AI Sight | 시야 범위 내 Actor | Sight Radius, Lose Sight Radius, Peripheral Vision Angle |
| AI Hearing | 소리를 발생시킨 Actor | Hearing Range |
| AI Damage | 데미지를 준 Actor | 자동 감지 (Apply Damage 시) |
| AI Touch | 물리적 접촉 Actor | 충돌 이벤트 기반 |
| AI Team | 같은/다른 팀 Actor | Team ID 기반 |
Sight (시각) 설정
시야 범위, 각도, 시야 상실 거리 설정
// AIController > Add Component > AIPerception
// AIPerception > Senses Config > Add > AI Sight Config
AI Sight Config
├─ Sight Radius: 1500 // 감지 거리 (cm)
├─ Lose Sight Radius: 2000 // 시야 상실 거리 (Sight보다 커야 함)
├─ Peripheral Vision Half Angle: 60 // 시야각 (도, 전방 기준 반각)
├─ Auto Success Range from Last Seen: 500 // 이 거리 이내면 자동 감지
├─ Point of View Backend: Default
│
└─ Detection by Affiliation
├─ Detect Enemies: True
├─ Detect Neutrals: True
└─ Detect Friendlies: False
// Lose Sight Radius > Sight Radius 필수!
// 히스테리시스: 감지 후 약간 멀어져도 바로 놓치지 않음
게임 실행 중 콘솔에 ai.debug.nav 1을 입력하거나, AIController를 선택한 상태에서 AI 디버그 뷰를 활성화하면 시야 범위가 녹색 원뿔로 표시됩니다.
Hearing (청각)과 자극 소스
소리 감지와 커스텀 자극 발생
AI Hearing 설정
AI Hearing Config
├─ Hearing Range: 3000 (cm)
└─ Detection by Affiliation: (Sight와 동일)
// 소리 발생시키기 (블루프린트에서)
[Report Noise Event] // UE 내장 노이즈 리포트
├─ Noise Emitter: Self
├─ Loudness: 1.0
└─ Tag: "Footstep"
// 또는 더 세밀한 제어:
[Make Noise] // Pawn의 MakeNoise 함수
├─ Loudness: 0.5
└─ Noise Instigator: Self
Stimuli Source Component
플레이어 Pawn에 AIPerceptionStimuliSourceComponent를 추가하고, 감지 가능한 감각을 등록합니다.
// BP_Player > Add Component > AI Perception Stimuli Source
AIPerceptionStimuliSourceComponent
├─ Auto Register as Source: True
└─ Register as Source for Senses:
├─ AISense_Sight // AI가 이 Actor를 볼 수 있음
└─ AISense_Hearing // AI가 이 Actor의 소리를 들을 수 있음
// 주의: 이 컴포넌트 없이도 Sight는 자동 감지되지만,
// 명시적으로 등록하면 더 안정적입니다
이벤트 처리와 BT 통합
Perception 이벤트를 Blackboard에 연결
// AIController에서 Perception 이벤트 처리
[Event BeginPlay]
└──> [Get AIPerception Component]
└──> [Bind Event: On Target Perception Updated]
└─ Event: HandlePerceptionUpdated
[HandlePerceptionUpdated] (Actor, Stimulus)
│
├──> [Break AIStimulus]
│ ├─ Was Successfully Sensed: Boolean
│ ├─ Stimulus Location: Vector
│ ├─ Age: Float (경과 시간)
│ └─ Type: (Sight, Hearing, Damage...)
│
└──> [Branch: Was Successfully Sensed]
│
├─ True (감지됨)
│ ├──> [Set Blackboard Value as Object]
│ │ ├─ Key: TargetActor
│ │ └─ Value: Actor
│ └──> [Set Blackboard Value as Bool]
│ ├─ Key: bHasTarget
│ └─ Value: True
│
└─ False (감지 상실)
├──> [Clear Blackboard Value] (TargetActor)
└──> [Set Blackboard Value as Vector]
├─ Key: LastKnownLocation
└─ Value: Stimulus Location
다중 감각 필터링
// 감각 타입별 다른 처리
[HandlePerceptionUpdated]
└──> [Break AIStimulus]
└─ Type ──> [Switch]
├─ Sight ──> [Set TargetActor] + [Set AlertLevel: Combat]
├─ Hearing ──> [Set InvestigateLocation] + [Set AlertLevel: Suspicious]
└─ Damage ──> [Set TargetActor] + [Set AlertLevel: Combat]
// 각 감각에 따라 다른 행동 트리 분기를 유도
Blackboard에 저장된 TargetActor를 BT의 Blackboard Decorator에서 확인하면, AI가 타겟을 감지했을 때 자동으로 전투 분기로 진입하고, 타겟을 잃었을 때 순찰 분기로 돌아갑니다. Observer Aborts: Both로 설정하면 Blackboard 값 변경 시 즉시 분기를 전환합니다.
핵심 요약
- AIPerceptionComponent는 AIController에, StimuliSourceComponent는 감지 대상 Pawn에 추가한다
- AI Sight의 Lose Sight Radius는 Sight Radius보다 커야 히스테리시스가 동작한다
- Report Noise Event로 소리 자극을 발생시키고, AI Hearing으로 감지한다
- OnTargetPerceptionUpdated 이벤트에서 감지/상실을 처리하여 Blackboard를 업데이트한다
- 감각 타입(Sight/Hearing/Damage)별로 다른 AlertLevel을 설정하여 행동을 분기한다
- BT Decorator의 Observer Aborts: Both로 Blackboard 변경 시 즉시 분기를 전환한다
도전 과제
배운 내용을 직접 실습해보세요
AIController에 AI Perception Component를 추가하고, AI Sight Config(시야각: 90도, 감지 반경: 1500)를 설정하세요. On Target Perception Updated 이벤트에서 감지/소실 여부를 분기하여, 감지 시 추적, 소실 시 마지막 위치 탐색 로직을 구현하세요.
AI Hearing Config를 추가하고, 플레이어 캐릭터에 AI Perception Stimuli Source Component를 부착하세요. Report Noise Event로 소리를 발생시키고, AI가 소리 위치로 이동하여 조사하는 로직을 만드세요.
시각 + 청각 + 데미지 3중 감각 시스템을 통합한 AI를 구현하세요. 시각으로 플레이어를 감지하면 즉시 공격, 청각으로 감지하면 조사 모드, 데미지를 받으면 소스 방향으로 회전하는 복합 반응 시스템을 만드세요. Sense별 우선순위도 설정하세요.