Verify validity of TAssetPtr/FStringAssetReference *without* loading the asset?

Does anyone know if there’s a way to verify the validity of a TAssetPtr or FStringAssetReference without actually loading the asset? As in, verifying that an asset actually exists at the location pointed to by the asset pointer or string reference. I’m loading a large number of assets by string patterns and I’d like to verify their validity when the asset references are created so I can warn about problems rather than having failures only when attempting to load the asset later.

TAssetPtr::IsValid() checks to see if Get() would return a valid object, which it wouldn’t if the asset hasn’t been loaded.

FStringAssetReference::IsValid() only checks to make sure the path isn’t empty, and does nothing to verify if an asset actually exists at that location.

The AssetRegistry is the only thing I can find which has functionality built to do this sort of thing, but it’s an editor-only module. I suppose that’s not a total dealbreaker, but it does force me to have redundant checks. (One failsafe for gameplay and then an actual proper error check with logging to notify me of missing assets in the editor.)

FAssetDatas can check if an asset is valid but can’t be used without the AssetRegistry.

Is there a better way of doing this?

Is using the FPlatformFileManager to check if the file exists a option for you?

I don’t think so?

The FPlatformFileManager is meant to actually look through the system’s file structure and locate files. When playing from the editor, this would be find since the uasset file would exist. However, playing from a packaged game, the game content will all be cooked and the file structure wouldn’t exist, so I’d expect the FPlatformFileManager to always fail to locate the asset, wouldn’t it?

Oh you´re right. Was not thinking about that. Than I actually don´t know if there is a existing functionality that also works with Packaged Builds without loading the Object =/

TAssetPtr also has:
“IsPending()” with which you can “Test if this does not point to a live UObject, but may in the future”

and

“IsNull()” with which you can “Test if this can never point to a live UObject”

When I am loading via TAssetPtrs I tend to do something along the lines of:

UClassType* Object = NULL;
if (!AssetPtr.IsNull())
{
    if (AssetPtr.IsPending())
    {
        //do loading, asynchronous or synchronous
    }
    //if asynchronous, below is in a post-load method/delegate
    if (AssetPtr.IsValid())
    {
        Object = AssetPtr.Get();
    }
}
if (Object)
{
    //Do whatever...
}

FStringAssetReferences can be converted to TAssetPtrs to perform the checks, but doesn’t have anything itself beyond checking if the file exists on disc (FPlatformFileManager); but like you said above, you can run into problems with packaged assets.

https://docs.unrealengine.com/latest/INT/API/Runtime/CoreUObject/Misc/FStringAssetReference/index.html

That looks right. Thanks! I saw this but assumed it had to do with checking to see if the asset was asych loading.

UAssetManager::GetAssetDataForPath could be the method you are looking for.