Fix custom json asset usage for game settings if loaded before game scripting module is loaded

This commit is contained in:
Wojtek Figat
2022-09-14 21:13:58 +02:00
parent f1adedd689
commit 0e523204d5
3 changed files with 7 additions and 3 deletions

View File

@@ -284,6 +284,8 @@ void JsonAsset::unload(bool isReloading)
bool JsonAsset::CreateInstance()
{
ScopeLock lock(Locker);
if (Instance)
return false;
// Try to scripting type for this data
const StringAsANSI<> dataTypeNameAnsi(DataTypeName.Get(), DataTypeName.Length());

View File

@@ -107,7 +107,7 @@ public:
ScriptingTypeHandle InstanceType;
/// <summary>
/// The deserialized unmanaged object instance (e.g. PhysicalMaterial).
/// The deserialized unmanaged object instance (e.g. PhysicalMaterial). Might be null if asset was loaded before binary module with that asset was loaded (use GetInstance for this case).
/// </summary>
void* Instance;
@@ -118,6 +118,7 @@ public:
template<typename T>
T* GetInstance() const
{
const_cast<JsonAsset*>(this)->CreateInstance();
return Instance && InstanceType.IsAssignableFrom(T::TypeInitializer) ? (T*)Instance : nullptr;
}