Optimize FindObject and TryFindObject in Object

This commit is contained in:
Wojtek Figat
2021-08-10 15:57:22 +02:00
parent 62c43f9f95
commit 27f2856e6d
4 changed files with 39 additions and 9 deletions

View File

@@ -754,13 +754,20 @@ ScriptingObject* Scripting::FindObject(Guid id, MClass* type)
if (result)
{
// Check type
if (result->Is(type))
if (!type || result->Is(type))
return result;
LOG(Warning, "Found scripting object with ID={0} of type {1} that doesn't match type {2}.", id, String(result->GetType().Fullname), String(type->GetFullName()));
return nullptr;
}
// Check if object can be an asset and try to load it
if (!type)
{
result = Content::LoadAsync(id, Asset::GetStaticClass());
if (!result)
LOG(Warning, "Unable to find scripting object with ID={0}", id);
return result;
}
if (type == ScriptingObject::GetStaticClass() || type->IsSubClassOf(Asset::GetStaticClass()))
{
Asset* asset = Content::LoadAsync(id, type);
@@ -796,7 +803,7 @@ ScriptingObject* Scripting::TryFindObject(Guid id, MClass* type)
#endif
// Check type
if (result && !result->Is(type))
if (result && type && !result->Is(type))
{
result = nullptr;
}