Import animations with FFbxImporter

Hey,

I’m using FFbxImporter to import FBX manually (this way I can scan folders, automatically import specific FBX files, etc). I managed to properly import Static meshes, as well as SkeletalMeshes. However, for these SkeletalMeshes, I’d also like to import their animations, and directly set the animation mode to “animation asset”, then set the animation I imported for it. So, like you would do in the editor, except automated in the code.

Here is my code :

if (FFbxImporter->ImportFromFile(UTF8_TO_TCHAR(file), TEXT("fbx"))) {
		TArray<FbxNode*> FbxMeshArray;
		FFbxImporter->FillFbxMeshArray(FFbxImporter->Scene->GetRootNode(), FbxMeshArray, FFbxImporter);
		UFbxSkeletalMeshImportData* importData = NewObject<UFbxSkeletalMeshImportData>(GetTransientPackage(), NAME_None, RF_NoFlags, NULL);
		for (int i = 0; i < FbxMeshArray.Num(); i++) {
			TArray<FbxNode*> array;
			array.Add(FbxMeshArray[i]);
			USkeletalMesh* mesh = (USkeletalMesh*)FFbxImporter->ImportSkeletalMesh(GetTransientPackage(), array, FbxMeshArray[i]->GetName(), RF_NoFlags, importData, 0);

			UFbxAnimSequenceImportData* animData = NewObject<UFbxAnimSequenceImportData>();
			FFbxImporter->SetupAnimationDataFromMesh(mesh, GetTransientPackage(), array, animData, TEXT("anim"));

			ASkeletalMeshActor* meshActor = World->SpawnActor<ASkeletalMeshActor>(ASkeletalMeshActor::StaticClass());
			meshActor->GetSkeletalMeshComponent()->SetAnimationMode(EAnimationMode::AnimationSingleNode);
			meshActor->GetSkeletalMeshComponent()->SetMobility(EComponentMobility::Movable);
			meshActor->GetSkeletalMeshComponent()->SetSkeletalMesh(mesh);
			meshActor->SetActorLabel(FbxMeshArray[i]->GetName());
		}
	}

So as you can see, I import the file, browse the SkeletalMeshes, import them. Then I tried SetupAnimationDataFromMesh but it doesn’t seem to do anything for me. My FBX file only has one animation in it. You can see I also use SetAnimationMode to tell the SkeletalMesh not to use an animation blueprint but a single animation. I imagine I’d have to use SkeletalMeshComponent::SetAnimation() but how can I get the UAnimationAsset that’s required ? How can I “extract” that from the FBX ? I don’t understand how FFbxImporter::ImportAnimation() works at all !

Thanks in advance !

Hi there,

May I know how you managed to import Static meshes, as well as SkeletalMeshes?