Importing an fbx in c++

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.

Which symbols specifically are unresolved? What build target are you attempting to build? You probably need to be on one of the *Editor targets since you’re using code that resides in editor modules.

Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol “public: static void __cdecl UnFbx::FFbxImporter::UpdateStaticMeshImportData(class UStaticMesh *,class UFbxStaticMeshImportData *)” (?UpdateStaticMeshImportData@FFbxImporter@UnFbx@@SAXPEAVUStaticMesh@@PEAVUFbxStaticMeshImportData@@@Z) referenced in function “private: virtual void __cdecl AUnityModelImporter::OnConstruction(struct FTransform const &)” (?OnConstruction@AUnityModelImporter@@EEAAXAEBUFTransform@@@Z) ProjectSoul C:\ProjectSoul\Intermediate\ProjectFiles\Module.UnityModelImporter.cpp.obj 1

That’s the error I get. :>

It seams that function is not externally exposed from UnrealEd module, if you look on header file:

https://github.com/EpicGames/UnrealEngine/blob/8696faa54bf2f89ca50d34e6fb3dcc461a810185/Engine/Source/Editor/UnrealEd/Public/FbxImporter.h#L710

It missing UNREALED_API which adds extern to the deceleration and exposes function in module dll preventing linker to enclose the code, you would modify this file in engine source code (which is not bad idea as long what you working on is plugin) or find other work around.

Do you think adding the functions would solve the empty file problem though?