diff --git a/Source/Engine/Content/Asset.h b/Source/Engine/Content/Asset.h index 2d2ba4b3f..be188b2b9 100644 --- a/Source/Engine/Content/Asset.h +++ b/Source/Engine/Content/Asset.h @@ -227,7 +227,7 @@ protected: bool onLoad(LoadAssetTask* task); void onLoaded(); - void onLoaded_MainThread(); + virtual void onLoaded_MainThread(); virtual void onUnload_MainThread(); #if USE_EDITOR virtual void onRename(const StringView& newPath) = 0; diff --git a/Source/Engine/Content/JsonAsset.cpp b/Source/Engine/Content/JsonAsset.cpp index b48ef02e5..9977a28e1 100644 --- a/Source/Engine/Content/JsonAsset.cpp +++ b/Source/Engine/Content/JsonAsset.cpp @@ -367,6 +367,20 @@ void JsonAsset::unload(bool isReloading) JsonAssetBase::unload(isReloading); } +void JsonAsset::onLoaded_MainThread() +{ + JsonAssetBase::onLoaded_MainThread(); + + // Special case for Settings assets to flush them after edited and saved in Editor + const StringAsANSI<> dataTypeNameAnsi(DataTypeName.Get(), DataTypeName.Length()); + const auto typeHandle = Scripting::FindScriptingType(StringAnsiView(dataTypeNameAnsi.Get(), DataTypeName.Length())); + if (Instance && typeHandle && typeHandle.IsSubclassOf(SettingsBase::TypeInitializer) && _isAfterReload) + { + _isAfterReload = false; + ((SettingsBase*)Instance)->Apply(); + } +} + bool JsonAsset::CreateInstance() { ScopeLock lock(Locker); @@ -409,13 +423,6 @@ bool JsonAsset::CreateInstance() } } - // Special case for Settings assets to flush them after edited and saved in Editor - if (typeHandle && typeHandle.IsSubclassOf(SettingsBase::TypeInitializer) && _isAfterReload) - { - _isAfterReload = false; - ((SettingsBase*)Instance)->Apply(); - } - return false; } diff --git a/Source/Engine/Content/JsonAsset.h b/Source/Engine/Content/JsonAsset.h index 0b6e3ca86..a8e89cec0 100644 --- a/Source/Engine/Content/JsonAsset.h +++ b/Source/Engine/Content/JsonAsset.h @@ -150,6 +150,7 @@ protected: // [JsonAssetBase] LoadResult loadAsset() override; void unload(bool isReloading) override; + void onLoaded_MainThread() override; private: bool CreateInstance();