Programming/UE5

[UE5] 패키징 앱에서 Blueprint 로드하기

Dorasima 2026. 4. 10. 14:54

런타임 로딩 메모 (패키징/Shipping)

패키징된 앱에서 Blueprint를 로드할 때는 에셋 경로보다 GeneratedClass(`_C`) 경로를 우선 사용한다.

- 에디터: `"/Path/Asset.Asset"`(UBlueprint) 로드가 동작할 수 있음
- 패키징 런타임: UBlueprint 원본은 제거/비보장될 수 있음
- 런타임 안정 경로: `"/Path/Asset.Asset_C"`(UClass)

`_C` 클래스로 `NewObject`를 만들면 CDO 기본값(머티리얼 셋 포인터 등)이 인스턴스에 적용된다.

static UClass* TryLoadAssetListClassFromPath(const FSoftObjectPath& Path)
{
	if (Path.IsNull()) {
		return nullptr;
	}

	// 1) 런타임 우선: GeneratedClass(_C)
	const FString ObjectPath = Path.ToString();
	const FString PackageName = FPackageName::ObjectPathToPackageName(ObjectPath);
	const FString AssetName = FPackageName::ObjectPathToObjectName(ObjectPath);

	if (!PackageName.IsEmpty() && !AssetName.IsEmpty()) {
		const FString ClassPath = PackageName + TEXT(".") + AssetName + TEXT("_C");
		if (UClass* Cls = FSoftClassPath(ClassPath).TryLoadClass<UVrmAssetListObject>()) {
			return Cls;
		}
	}

	// 2) 에디터/개발환경 fallback
	if (UObject* Loaded = Path.TryLoad()) {
		if (const UBlueprint* BP = Cast<UBlueprint>(Loaded)) {
			if (BP->GeneratedClass && BP->GeneratedClass->IsChildOf(UVrmAssetListObject::StaticClass())) {
				return BP->GeneratedClass;
			}
		}
		if (UClass* Cls = Cast<UClass>(Loaded)) {
			if (Cls->IsChildOf(UVrmAssetListObject::StaticClass())) {
				return Cls;
			}
		}
	}

	return nullptr;
}