diff --git a/Source/Engine/Content/Asset.h b/Source/Engine/Content/Asset.h index 8cb801647..a831ee773 100644 --- a/Source/Engine/Content/Asset.h +++ b/Source/Engine/Content/Asset.h @@ -106,7 +106,7 @@ public: public: /// - /// Gets the path to the asset storage. + /// Gets the path to the asset storage file. In Editor it reflects the actual file, in cooked Game, it fakes the Editor path to be informative for developers. /// API_PROPERTY() virtual const String& GetPath() const = 0; diff --git a/Source/Engine/Content/BinaryAsset.cpp b/Source/Engine/Content/BinaryAsset.cpp index 5b79c1b7d..7b8066d18 100644 --- a/Source/Engine/Content/BinaryAsset.cpp +++ b/Source/Engine/Content/BinaryAsset.cpp @@ -446,7 +446,12 @@ void BinaryAsset::OnDeleteObject() const String& BinaryAsset::GetPath() const { +#if USE_EDITOR return Storage ? Storage->GetPath() : String::Empty; +#else + // In build all assets are packed into packages so use ID for original path lookup + return Content::GetRegistry()->GetAssetPath(_id); +#endif } /// diff --git a/Source/Engine/Content/Cache/AssetsCache.cpp b/Source/Engine/Content/Cache/AssetsCache.cpp index 42a61c2a3..e6ee03d39 100644 --- a/Source/Engine/Content/Cache/AssetsCache.cpp +++ b/Source/Engine/Content/Cache/AssetsCache.cpp @@ -233,6 +233,11 @@ bool AssetsCache::Save(const StringView& path, const Registry& entries, const Pa return false; } +const String& AssetsCache::GetAssetPath(const Guid& id) const +{ + return _registry[id].Info.Path; +} + bool AssetsCache::FindAsset(const StringView& path, AssetInfo& info) { PROFILE_CPU(); diff --git a/Source/Engine/Content/Cache/AssetsCache.h b/Source/Engine/Content/Cache/AssetsCache.h index f81fc920d..25942faec 100644 --- a/Source/Engine/Content/Cache/AssetsCache.h +++ b/Source/Engine/Content/Cache/AssetsCache.h @@ -128,6 +128,13 @@ public: public: + /// + /// Finds the asset path by id. + /// + /// The asset id. + /// The asset path, or empty if failed to find. + const String& GetAssetPath(const Guid& id) const; + /// /// Finds the asset info by path. /// diff --git a/Source/Engine/Content/JsonAsset.cpp b/Source/Engine/Content/JsonAsset.cpp index aade1a29c..18e373246 100644 --- a/Source/Engine/Content/JsonAsset.cpp +++ b/Source/Engine/Content/JsonAsset.cpp @@ -7,7 +7,9 @@ #else #include "Storage/ContentStorageManager.h" #endif +#include "Content.h" #include "FlaxEngine.Gen.h" +#include "Cache/AssetsCache.h" #include "Engine/Core/Log.h" #include "Engine/Serialization/JsonTools.h" #include "Engine/Content/Factories/JsonAssetFactory.h" @@ -39,7 +41,12 @@ String JsonAssetBase::GetData() const const String& JsonAssetBase::GetPath() const { +#if USE_EDITOR return _path; +#else + // In build all assets are packed into packages so use ID for original path lookup + return Content::GetRegistry()->GetAssetPath(_id); +#endif } #if USE_EDITOR @@ -94,7 +101,6 @@ Asset::LoadResult JsonAssetBase::loadAsset() { // Load data (raw json file in editor, cooked asset in build game) #if USE_EDITOR - BytesContainer data; if (File::ReadAllBytes(GetPath(), data)) { @@ -105,9 +111,7 @@ Asset::LoadResult JsonAssetBase::loadAsset() { return LoadResult::MissingDataChunk; } - #else - // Get the asset storage container but don't load it now const auto storage = ContentStorageManager::GetStorage(GetPath(), true); if (!storage) @@ -125,7 +129,6 @@ Asset::LoadResult JsonAssetBase::loadAsset() if (storage->LoadAssetChunk(chunk)) return LoadResult::CannotLoadData; auto& data = chunk->Data; - #endif // Parse json document