diff --git a/Source/Engine/Content/Assets/Model.cpp b/Source/Engine/Content/Assets/Model.cpp
index 22de66263..3da53ea6b 100644
--- a/Source/Engine/Content/Assets/Model.cpp
+++ b/Source/Engine/Content/Assets/Model.cpp
@@ -682,7 +682,11 @@ bool Model::GenerateSDF(float resolutionScale, int32 lodIndex, bool cacheData, f
#if USE_EDITOR
// Set asset data
if (cacheData)
- GetOrCreateChunk(15)->Data.Copy(sdfStream.GetHandle(), sdfStream.GetPosition());
+ {
+ auto chunk = GetOrCreateChunk(15);
+ chunk->Data.Copy(sdfStream.GetHandle(), sdfStream.GetPosition());
+ chunk->Flags |= FlaxChunkFlags::KeepInMemory; // Prevent GC-ing chunk data so it will be properly saved
+ }
#endif
return false;
diff --git a/Source/Engine/Content/Storage/FlaxChunk.h b/Source/Engine/Content/Storage/FlaxChunk.h
index 5281aea28..7aa0daf8e 100644
--- a/Source/Engine/Content/Storage/FlaxChunk.h
+++ b/Source/Engine/Content/Storage/FlaxChunk.h
@@ -11,7 +11,7 @@
enum class FlaxChunkFlags
{
///
- /// The none.
+ /// Nothing.
///
None = 0,
@@ -19,6 +19,11 @@ enum class FlaxChunkFlags
/// Compress chunk data using LZ4 algorithm.
///
CompressedLZ4 = 1,
+
+ ///
+ /// Prevents chunk file data from being unloaded if unused for a certain amount of time. Runtime-only flag, not saved with the asset.
+ ///
+ KeepInMemory = 2,
};
DECLARE_ENUM_OPERATORS(FlaxChunkFlags);
diff --git a/Source/Engine/Content/Storage/FlaxStorage.cpp b/Source/Engine/Content/Storage/FlaxStorage.cpp
index c3e377110..29bcd5bfc 100644
--- a/Source/Engine/Content/Storage/FlaxStorage.cpp
+++ b/Source/Engine/Content/Storage/FlaxStorage.cpp
@@ -943,7 +943,8 @@ bool FlaxStorage::Create(WriteStream* stream, const AssetInitData* data, int32 d
{
FlaxChunk* chunk = chunks[i];
stream->WriteBytes(&chunk->LocationInFile, sizeof(chunk->LocationInFile));
- stream->WriteInt32((int32)chunk->Flags);
+ FlaxChunkFlags flags = chunk->Flags & ~(FlaxChunkFlags::KeepInMemory); // Skip saving runtime-only flags
+ stream->WriteInt32((int32)flags);
}
#if ASSETS_LOADING_EXTRA_VERIFICATION
@@ -1410,7 +1411,7 @@ void FlaxStorage::Tick(double time)
{
auto chunk = _chunks.Get()[i];
const bool wasUsed = (time - chunk->LastAccessTime) < unusedDataChunksLifetime;
- if (!wasUsed && chunk->IsLoaded())
+ if (!wasUsed && chunk->IsLoaded() && EnumHasNoneFlags(chunk->Flags, FlaxChunkFlags::KeepInMemory))
{
chunk->Unload();
}