UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
WorldPartitionCookPackage.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#if WITH_EDITOR
5#include "CoreMinimal.h"
6#include "Hash/CityHash.h"
7#include "Misc/Paths.h"
9#include "UObject/Package.h"
10#include "Hash/Blake3.h"
11
14
15#else
17#endif
18
20{
21#if WITH_EDITOR
22
23 enum class EType
24 {
25 Unknown,
26 Level,
28 };
29
30 using IDType = uint64;
31
32 static IDType MakeCookPackageID(const FString& InRoot, const FString& InRelativeFilename)
33 {
34 check(!InRoot.IsEmpty() && !InRelativeFilename.IsEmpty());
35 check(InRoot[0] == '/' && InRoot[InRoot.Len() - 1] != '/'); // Root is assumed to be in the format "/Root"
36 check(InRelativeFilename[0] == '/' && InRelativeFilename[InRelativeFilename.Len() - 1] != '/'); // RelativeFileName is assumed to be in the format "/Relativefilename
37
38 // Avoid doing string copies as this function is often called during cook when bridging between Cook code & WorldPartition code.
39 // Compute a hash for both InRoot & InRelativeFilename. Then combine them instead of creating a new fullpath string and computing the hash on it.
40 uint64 RootHash = CityHash64(reinterpret_cast<const char*>(*InRoot), InRoot.Len() * sizeof(TCHAR));
41 uint64 RelativePathHash = CityHash64(reinterpret_cast<const char*>(*InRelativeFilename), InRelativeFilename.Len() * sizeof(TCHAR));
43 }
44
45 // PathComponents (Root & RelativePath members) need to follow the "/<PathComponent>" format for the PackageId computation to work.
46 static FString SanitizePathComponent(const FString& Path)
47 {
48 FString SanitizedPath = TEXT("/") + Path;
50
51 if (SanitizedPath[SanitizedPath.Len() - 1] == '/')
52 {
53 SanitizedPath.RemoveAt(SanitizedPath.Len() - 1, 1);
54 }
55
56 return SanitizedPath;
57 }
58
59 static FString MakeGeneratedFullPath(const FString& InRoot, const FString& InRelativeFilename)
60 {
62 FullPath += TEXT("/");
63 FullPath += InRoot;
64 FullPath += GeneratedFolder;
65 FullPath += InRelativeFilename;
66
67 return FPaths::RemoveDuplicateSlashes(*FullPath);
68 }
69
73 PackageId(MakeCookPackageID(Root, RelativePath)),
74 Type(InType),
76 {
77 }
78
79 FString GetFullGeneratedPath() const { return MakeGeneratedFullPath(Root, RelativePath); }
80
81 UPackage* GetPackage() const { return FindObject<UPackage>(nullptr, *GetFullGeneratedPath()); }
82
83 const FString Root;
84 const FString RelativePath;
85 const IDType PackageId;
86 const EType Type;
88#endif
89
91 static FStringView GetGeneratedFolderName() { return FStringView(&GeneratedFolder[1], GeneratedFolder.Len() - 2); }
92
93private:
94 static constexpr FStringView GeneratedFolder = TEXTVIEW("/_Generated_/");
95};
@ Generic
Definition AndroidInputInterface.h:108
#define check(expr)
Definition AssertionMacros.h:314
uint64 CityHash64(const char *s, uint32 len)
Definition CityHash.cpp:388
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
TStringView< TCHAR > FStringView
Definition StringFwd.h:45
#define TEXTVIEW(str)
Definition StringView.h:553
Definition Blake3.h:94
static CORE_API void RemoveDuplicateSlashes(FString &InPath)
Definition Paths.cpp:1376
Definition StringBuilder.h:509
constexpr int32 Len() const
Definition StringView.h:174
Definition Package.h:216
Definition Blake3.h:27
Definition WorldPartitionCookPackage.h:20
static FStringView GetGeneratedFolderName()
Definition WorldPartitionCookPackage.h:91