Last active
January 4, 2024 07:20
-
-
Save yujuiting/780ecb9be599b1fd02dddb91c3668a75 to your computer and use it in GitHub Desktop.
Unreal Engine 4: Dynamic load uasset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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); |
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
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
Very usefull thanks for this!