diff --git a/Source/Editor/Cooker/Steps/CookAssetsStep.cpp b/Source/Editor/Cooker/Steps/CookAssetsStep.cpp index 7f2824c42..be4dca78d 100644 --- a/Source/Editor/Cooker/Steps/CookAssetsStep.cpp +++ b/Source/Editor/Cooker/Steps/CookAssetsStep.cpp @@ -1081,12 +1081,12 @@ bool CookAssetsStep::Perform(CookingData& data) data.StepProgress(TEXT("Creating assets cache"), Step2ProgressEnd); - // Create asset paths mapping for the root assets. + // Create asset paths mapping for the assets. // Assets mapping is use to convert paths used in Content::Load(path) into the asset id. - // It fixes the issues when in build game all assets are in the packages while engine parts are requesting in-build assets by name. + // It fixes the issues when in build game all assets are in the packages and are requested by path. // E.g. game settings are loaded from `Content/GameSettings.json` file which is packages in one of the packages. - // Additionally it improves the in-build assets loading performance. - for (auto i = data.RootAssets.Begin(); i.IsNotEnd(); ++i) + // Additionally it improves the in-build assets loading performance (no more registry linear lookup for path by dictionary access). + for (auto i = data.Assets.Begin(); i.IsNotEnd(); ++i) { if (Content::GetAssetInfo(i->Item, assetInfo)) { diff --git a/Source/Engine/Content/Cache/AssetsCache.cpp b/Source/Engine/Content/Cache/AssetsCache.cpp index 049064b63..71faef533 100644 --- a/Source/Engine/Content/Cache/AssetsCache.cpp +++ b/Source/Engine/Content/Cache/AssetsCache.cpp @@ -245,12 +245,22 @@ bool AssetsCache::FindAsset(const StringView& path, AssetInfo& info) { return FindAsset(id, info); } +#if !USE_EDITOR + if (FileSystem::IsRelative(path)) + { + // Additional check if user provides path relative to the project folder (eg. Content/SomeAssets/MyFile.json) + const String absolutePath = Globals::ProjectFolder / *path; + if (_pathsMapping.TryGet(absolutePath, id)) + { + return FindAsset(id, info); + } + } +#endif // Find asset in registry for (auto i = _registry.Begin(); i.IsNotEnd(); ++i) { auto& e = i->Value; - if (e.Info.Path == path) { // Validate file exists diff --git a/Source/Engine/Platform/Base/FileSystemBase.cpp b/Source/Engine/Platform/Base/FileSystemBase.cpp index 9ec1bc095..4eeeee6e2 100644 --- a/Source/Engine/Platform/Base/FileSystemBase.cpp +++ b/Source/Engine/Platform/Base/FileSystemBase.cpp @@ -98,11 +98,11 @@ void FileSystemBase::NormalizePath(String& path) } } -bool FileSystemBase::IsRelative(const String& path) +bool FileSystemBase::IsRelative(const StringView& path) { const bool isRooted = (path.Length() >= 2 && StringUtils::IsAlpha(path[0]) && path[1] == ':') || - path.StartsWith(TEXT("\\\\")) || + path.StartsWith(StringView(TEXT("\\\\"), 2), StringSearchCase::CaseSensitive) || path.StartsWith('/') || path.StartsWith('\\') || path.StartsWith('/'); diff --git a/Source/Engine/Platform/Base/FileSystemBase.h b/Source/Engine/Platform/Base/FileSystemBase.h index 1e0db6aa7..bc8aadd3f 100644 --- a/Source/Engine/Platform/Base/FileSystemBase.h +++ b/Source/Engine/Platform/Base/FileSystemBase.h @@ -104,7 +104,7 @@ public: /// /// Input path to check /// True if input path is relative one, otherwise false - static bool IsRelative(const String& path); + static bool IsRelative(const StringView& path); /// /// Retrieves file extension (without a dot)