Fix custom json asset usage for game settings if loaded before game scripting module is loaded
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user