Hello, I am trying to develop a modular way to pull our resources from our projects on a case-by-case basis without having to write specific code for each use case.
I have developed a custom class that does what it is supposed to when using textures or static meshes but when I attempted to use it for animation instance blueprints it returns an array with the correct number of elements but which are all “None” in value instead of containing the blueprints.
Here is our code:
TArray<UObject*> UItemManager::GetAssets(FString contentFldPath, bool bLoadSubFolders, UClass* assetType) {
TArray<UObject*> rtnArr = TArray<UObject*>();
TArray<FString> fNames = TArray<FString>();
FString ext;
FString rootPath = FPaths::ConvertRelativePathToFull(FPaths::GameDir()) + "Content/" + contentFldPath + "/";
IFileManager& fManager = IFileManager::Get();
if (!ext.Contains(TEXT("*"))) {
if (ext == "") {
ext = "*.*";
}
else {
ext = (ext.Left(1) == ".") ? "*" : "*." + ext;
}
}
if (bLoadSubFolders) {
fManager.FindFilesRecursive(fNames, *rootPath, *ext, true, false);
}
else {
fManager.FindFiles(fNames, *(rootPath + ext), true, false);
}
for (int32 i1 = 0; i1 < fNames.Num(); i1++) {
FString fPath;
if (bLoadSubFolders) {
int32 lastFSlash = fNames[i1].Find("/", ESearchCase::IgnoreCase, ESearchDir::FromEnd);
FString file = fNames[i1].RightChop(lastFSlash + 1);
FString fld = fNames[i1].RightChop(fNames[i1].Find(contentFldPath, ESearchCase::CaseSensitive, ESearchDir::FromEnd) + contentFldPath.Len());
fld = fld.LeftChop(file.Len() + 1);
fPath = assetType->GetFName().ToString() + "'/Game/" + contentFldPath + fld + "/" + file + "'";
}
else {
fPath = assetType->GetFName().ToString() + "'/Game/" + contentFldPath + "/" + fNames[i1].LeftChop(7) + "." + fNames[i1].LeftChop(7) + "'";
}
UObject* loadObject = StaticLoadObject(assetType, NULL, *fPath);
rtnArr.Add(loadObject);
}
return rtnArr;
}
Here is how we are calling this function from the blueprint:
The folder path parameter we are passing through is correct, “Items/Small/Easy/Blueprints” and as you can see the asset type is set to Anim Instance. Not sure if we have the right class or if this method of getting the asset won’t work for this kind of file.
Any suggestions?
Update
Turns out I was using the wrong class, I needed to use Animation Blueprint instead. Now I have a new problem. When I get back my TArray all of my assets are straight objects. I need to cast them to Animation Blueprints but there is no node to do so, it only brings up the Animation Blueprints I already have created (the ones I have stored in the folders I am bringing in through the class).
Is there some process to do this easily? Like comparing the object to an existing animation blueprint and casting it to that specific one? I don’t want to do this if possible as it sounds like it would take a lot of nodes to do something that we should just be able to do with one cast for the general asset type.