Unity rotation fix for FBX

I’ve only tested this for static meshes but it fixes that 90 degree rotation issue when importing a Blender FBX into Unity:

import bpy

filePath = "G:\\!GDG\\art\\!GoHere\\Crate\\Standard\\"

#concatenate subfolder
PathSubFolder = "" #"Crate_Baking_Low\\"
print (filePath)
    
    #rotate x -90 degrees, apply rotation, rotate back x 90 degress
bpy.ops.transform.rotate(value=-1.5708, axis=(1, 0, 0), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
    
bpy.ops.object.transform_apply(location=False, rotation=True, scale=False)

bpy.ops.transform.rotate(value=1.5708, axis=(1, 0, 0), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
    
obName = bpy.context.scene.objects.active.name + ".fbx"
print(obName)   
    #write the files
bpy.ops.export_scene.fbx(filepath = filePath + PathSubFolder +obName, use_selection = True)

#apply the rotation again so everything is reset
bpy.ops.object.transform_apply(location=False, rotation=True, scale=False)

There is no need to modify the code for that, you can already select (in nearly all exporters under Blender) which axis is “forward”, and which one is “top”, to adapt the exported scene/object to the orientation used by the target app. Don’t know off hand which settings are correct for Unity, but a few tests should allow to find them quickly…