From 9f9564895e158cf07bb9fcddc945a3939430c928 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 25 Oct 2024 19:02:31 +0200 Subject: [PATCH] Fix collecting referenced asses from `Animation` asset #3013 --- Source/Engine/Content/Assets/Animation.cpp | 30 ++++++++++++++++++++++ Source/Engine/Content/Assets/Animation.h | 3 +++ 2 files changed, 33 insertions(+) diff --git a/Source/Engine/Content/Assets/Animation.cpp b/Source/Engine/Content/Assets/Animation.cpp index f65a1c3ba..261394441 100644 --- a/Source/Engine/Content/Assets/Animation.cpp +++ b/Source/Engine/Content/Assets/Animation.cpp @@ -12,6 +12,8 @@ #include "Engine/Serialization/MemoryReadStream.h" #if USE_EDITOR #include "Engine/Serialization/MemoryWriteStream.h" +#include "Engine/Serialization/JsonWriters.h" +#include "Engine/Content/JsonAsset.h" #include "Engine/Level/Level.h" #endif @@ -486,6 +488,34 @@ bool Animation::Save(const StringView& path) return false; } +void Animation::GetReferences(Array& assets, Array& files) const +{ + BinaryAsset::GetReferences(assets, files); + + for (const auto& e : Events) + { + for (const auto& k : e.Second.GetKeyframes()) + { + if (k.Value.Instance) + { + // Collect refs from Anim Event data (as Json) + rapidjson_flax::StringBuffer buffer; + CompactJsonWriter writer(buffer); + writer.StartObject(); + k.Value.Instance->Serialize(writer, nullptr); + writer.EndObject(); + JsonAssetBase::GetReferences(StringAnsiView((char*)buffer.GetString(), buffer.GetSize()), assets); + } + } + } + + // Add nested animations + for (const auto& e : NestedAnims) + { + assets.Add(e.Second.Anim.GetID()); + } +} + #endif uint64 Animation::GetMemoryUsage() const diff --git a/Source/Engine/Content/Assets/Animation.h b/Source/Engine/Content/Assets/Animation.h index b90fbdb73..f287fbd72 100644 --- a/Source/Engine/Content/Assets/Animation.h +++ b/Source/Engine/Content/Assets/Animation.h @@ -153,6 +153,9 @@ public: public: // [BinaryAsset] +#if USE_EDITOR + void GetReferences(Array& assets, Array& files) const override; +#endif uint64 GetMemoryUsage() const override; void OnScriptingDispose() override;