I recently found something unusual in Unreal Engine’s source code.
Specifically, I have been studying the UFbxFactory::FactoryCreateFile()
function, which is responsible for importing FBX files into the editor and creating corresponding assets—either StaticMesh
or SkeletalMesh
.
Inside this function, a variable named BaseSkeletalMesh
may not be properly assigned a value, which could result in two if
statements never evaluating to true
.
This function is quite large, spanning from line 159 to 877 in FbxFactory.h
, so I cannot post the entire source code here. Instead, I am providing a highly simplified pseudocode version:
UObject* UFbxFactory::FactoryCreateFile
(
UClass* Class,
UObject* InParent,
FName Name,
EObjectFlags Flags,
const FString& InFilename,
const TCHAR* Parms,
FFeedbackContext* Warn,
bool& bOutOperationCanceled
)
{
...
if (ImportOptions)
{
...
if (!FbxImporter->ImportFromFile(*UFactory::CurrentFilename, Type, true))
{
...
}
else // Execution continues only if ImportFromFile succeeds
{
...
if (RootNodeToImport && InterestingNodeCount > 0)
{
...
if (ImportUI->MeshTypeToImport == FBXIT_StaticMesh) // Static mesh
{
...
}
else if (ImportUI->MeshTypeToImport == FBXIT_SkeletalMesh) // Skeletal mesh
{
...
for (int32 i = 0; i < SkelMeshArray.Num() && !bOperationCanceled; i++)
{
USkeletalMesh* BaseSkeletalMesh = nullptr; // BaseSkeletalMesh is declared here (line 634)
... // No assignment to BaseSkeletalMesh in this section
for (int32 LODIndex = 0; LODIndex < MaxNumberOfLOD && !bOperationCanceled; LODIndex++)
{
... // No assignment to BaseSkeletalMesh in this section either
if (LODIndex == 0 && SkelMeshNodeArray.Num() != 0) // Line 695; First if-statement
{
... // BaseSkeletalMesh is assigned a value here
}
else if (BaseSkeletalMesh && SkelMeshNodeArray[0]->GetMesh() == nullptr) // Line 731; Second if-statement
{
...
}
else if (BaseSkeletalMesh) // The base skeletal mesh is imported successfully (Line 745; Third if-statement)
{
...
}
// Line 772
}
...
}
...
}
else if (ImportUI->MeshTypeToImport == FBXIT_Animation) // Animation
{
...
}
}
else
{
...
}
...
}
...
}
...
return CreatedObject;
}
Simply put, BaseSkeletalMesh
is declared but not assigned a value before the first if
statement at line 695.
Since BaseSkeletalMesh
is only assigned a value inside the first if-statement, this means that if the first condition is not met, the second and third if-statements at lines 731 and 745 will always evaluate to false.
As a result, lines 731-772 appear to be dead code—they should never be executed in practice.
This might not cause a critical bug, but it could indicate a loss of some intended functionality.
Questions
- Could this be an oversight by the developers, or was it intentional?
- I am using UE4.27, has this issue been fixed in UE5?
- If this is indeed dead code, should I report it to Epic Games as a bug?