플러그인에서 에셋·콘텐츠·입력·설정을 안전하게 다루기
30강. 플러그인에서 에셋·콘텐츠·입력·설정을 안전하게 다루기
1. 이번 강의에서 해결할 문제
Plugin이 /Game/UI/WBP_Interact나 프로젝트 Input Action을 Hard Reference하면 다른 프로젝트에서 즉시 깨집니다. Plugin Content 경로를 문자열로 하드코딩해도 Plugin 이름 변경과 Mount 시점에 취약합니다. 입력을 Plugin이 강제로 바꾸면 기존 매핑과 충돌합니다.
2. 학습 목표
3. 핵심 개념
재사용 Plugin은 세 원칙을 따릅니다.
- 핵심 기능은 에셋 없이도 동작한다.
- 선택적 에셋은 Soft Reference로 늦게 읽고 실패를 처리한다.
- 플레이어 입력은 프로젝트가 Binding하고 Plugin의 명령 API를 호출한다.
Plugin 이름이 ReusableInteraction이면 Content Mount Root는 일반적으로 /ReusableInteraction/입니다. 실제 Mount 상태는 IPluginManager와 Asset Registry로 확인하며 /Game으로 가정하지 않습니다.
4. 단계별 실습
Descriptor가 Content 포함을 명시합니다.
{
"CanContainContent": true,
"Modules": [
{
"Name": "ReusableInteraction",
"Type": "Runtime",
"LoadingPhase": "Default"
}
]
}
설정에는 직접 UObject Pointer 대신 Soft Reference를 둡니다.
UPROPERTY(Config, EditAnywhere, Category="Presentation",
meta=(AllowedClasses="/Script/Engine.Texture2D"))
TSoftObjectPtr<UTexture2D> PromptIcon;
비동기 로딩이 필요한 UI 계층은 Soft Object Path를 받아 자체 Streamable Handle을 소유합니다. 핵심 상호작용 판정은 아이콘 로딩을 기다리지 않습니다.
#include "Interfaces/IPluginManager.h"
FString GetReusableInteractionContentDirectory()
{
const TSharedPtr<IPlugin> Plugin =
IPluginManager::Get().FindPlugin(TEXT("ReusableInteraction"));
if (!Plugin.IsValid())
{
UE_LOG(LogReusableInteraction, Error,
TEXT("ReusableInteraction plugin is not mounted"));
return FString();
}
return Plugin->GetContentDir();
}
입력은 소비 프로젝트에 둡니다.
void APlayerCharacter::SetupPlayerInputComponent(
UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
UEnhancedInputComponent* Enhanced =
CastChecked<UEnhancedInputComponent>(PlayerInputComponent);
Enhanced->BindAction(
InteractAction,
ETriggerEvent::Started,
this,
&APlayerCharacter::HandleInteract);
}
void APlayerCharacter::HandleInteract()
{
if (UInteractionComponent* Interaction =
FindComponentByClass<UInteractionComponent>())
{
Interaction->TryInteract();
}
}
Plugin이 Enhanced Input을 직접 의존하지 않으므로 키보드, 게임패드, AI, 자동 테스트가 모두 같은 TryInteract 명령을 호출할 수 있습니다. 별도 선택 Module로 Input Adapter를 제공하는 설계는 가능하지만 Runtime Core의 필수 의존으로 만들지 않습니다.
5. 코드가 동작하는 이유
Soft Reference는 에셋 경로를 저장하되 객체를 즉시 Load하거나 Cook 의존으로 강제하지 않습니다. 입력 Binding을 프로젝트가 소유하면 기존 Input Mapping Context와 충돌하지 않습니다. Plugin의 핵심 C++ 경로는 콘텐츠나 입력 장치 없이도 자동 테스트할 수 있습니다.
6. 자주 하는 실수와 해결법
7. 직접 실습
8. 이해 점검 질문 3개
9. 핵심 요약
플러그인에서 에셋·콘텐츠·입력·설정을 안전하게 다루기 미니 퀴즈
선택 즉시 정답과 해설을 확인할 수 있습니다. 결과는 이 브라우저에만 저장됩니다.
학습을 마쳤나요?
직접 실습과 점검 질문까지 확인한 뒤 완료로 표시하세요.