Hello.
I’m trying to import an fbx in c++ in the editor(not runtime). I’ve been looking at various posts and source files, but to no avail.
My current code is this:
UnFbx::FFbxImporter* FbxImporter = UnFbx::FFbxImporter::GetInstance();
if (FbxImporter->ImportFromFile(FBXFiles[Index], TEXT("fbx")))
{
TArray<FbxNode*> FbxMeshArray;
FbxImporter->FillFbxMeshArray(FbxImporter->Scene->GetRootNode(), FbxMeshArray, FbxImporter);
UFbxStaticMeshImportData* ImportData = NewObject<UFbxStaticMeshImportData>(GetTransientPackage(), NAME_None, RF_NoFlags, NULL);
for (int i = 0; i < FbxMeshArray.Num(); i++)
{
UStaticMesh* ImportedMesh = (UStaticMesh*)FbxImporter->ImportStaticMesh(GetTransientPackage(), FbxMeshArray[i], FbxMeshArray[i]->GetName(), RF_NoFlags, ImportData);
FString PackageName = TEXT("/Game/");
PackageName += ImportedMesh->GetName();
UPackage* Package = CreatePackage(NULL, *PackageName);
Package->FullyLoad();
Package->MarkPackageDirty();
FAssetRegistryModule::AssetCreated(ImportedMesh);
FString PackageFileName = FPackageName::LongPackageNameToFilename(PackageName, FPackageName::GetAssetPackageExtension());
bool bSaved = UPackage::SavePackage(Package, ImportedMesh, EObjectFlags::RF_Public | EObjectFlags::RF_Standalone, *PackageFileName, GError, nullptr, true, true, SAVE_NoError);
}
}
I’ve also tried adding
FbxImporter->PostImportStaticMesh(ImportedMesh, FbxMeshArray);
FbxImporter->UpdateStaticMeshImportData(ImportedMesh, ImportData);
after the ImportStaticMesh function, but then I get a linker error(unresolved symbols). I have included FBX, Engine, Core, UnrealEd, etc in my build file, but that doesn’t help. Though I don’t even know if that’ll fix it.
It does create a file, but with nothing in it. Any ideas?
Also, FbxNode seems to give me an intellisense error no matter what I include.