Skip to content

Instantly share code, notes, and snippets.

@yujuiting
Last active January 4, 2024 07:20
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save yujuiting/780ecb9be599b1fd02dddb91c3668a75 to your computer and use it in GitHub Desktop.
Save yujuiting/780ecb9be599b1fd02dddb91c3668a75 to your computer and use it in GitHub Desktop.
Unreal Engine 4: Dynamic load uasset
/*
load uasset from file path.
*/
FString filepath("/Game/an_animation_file"); // without extension, path start with `/Game`, `/Game` refer-> `Content` folder in real.
FStringAssetReference asset_stream_ref(filepath);
TAssetPtr<UAnimationAsset> animation_asset(asset_stream_ref);
UAnimationAsset* animation = animation_asset.LoadSynchronous();
bool isValid = animation_asset.IsValid();
bool isNull = animation_asset.IsNull();
bool isPending = animation_asset.IsPending();
/*
load uassets from folder path.
*/
FString folderpath("/Game/animations_folder");
UObjectLibrary* lib = UObjectLibrary::CreateLibrary(UAnimationAsset::StaticClass(), false, GIsEditor);
lib->AddToRoot();
lib->LoadAssetDataFromPath(folderpath);
lib->LoadAssetsFromAssetData();
TArray<FAssetData> asset_data;
lib->GetAssetDataList(asset_data);
@antoinefortin
Copy link

Very usefull thanks for this!

@ArthurNvs
Copy link

ArthurNvs commented Nov 24, 2019

I'm here to thank you.. thank you a lot..

To be honest, I'm not entirely capable of understanding everything that is happening here, but you helped someone to start understanding

@linqen
Copy link

linqen commented Aug 24, 2023

Super useful!
Unreal documentation says we should use AssetRegistry now, but there is no function there that does this so clean and effective.

Thank you for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment