Blender to Unity FBX export offset in animation

Hello,
I’m trying to export my first, very simple animation of a recoil of a turret and am trying to export it via FBX into Unity.

So I have this turret, two objects (base and barrel). Base is at 0,0,0 and the barrel has a slight offset - a bit up and a bit ‘forward’ in the barrel-direction - so it’s in the correct position in Blender. I have an animation using delta-offsets only in the z-direction (the green value) which moves the barrel backward and forward a bit (nothing really complex).

So exporting to FBX and into unity, any object I export (irrelevant of where it’s positioned, even if it’s not in the origin) ends up in the correct place (turret looks fine) as if it uses the object-origin.
I’m wondering the matrix/position of my barrel is at 0,0,0 with the “graphics data, specifically y-value of the vertices” having an offset with Y=2… Or if the matrix/position is at y=2 (specifically using the xyz of the object-origin), and the “graphics data vertices” being near the origin.

The moment I use the animation, the barrel is “too high” (probably the height difference is added once twice for some reason). Observations: The animation is responsible for adding the “2.0x” to the Y-value (without the animation y=zero and it is positioned correctly). Also, it seems to ignore my delta-animation in Z because it looks like an animation in XYZ - and at appears to be absolute since somewhere it’s getting the 2.x value.

So positioning my the barrel at x/y/z offset of 0,0,0 and exporting (and reverting so it’s in the correct place to be able to animate again) looks like this: That looks better, but still no exact match but “slightly” too high compared to the first screenshot.


I tried so many things which don’t work (position, delta-position, apply position, centered at origin, export options), that I’m not sure if my general approach is completely wrong, if I’m overlooking something silly.
Any ideas anymore?

Note: This could probably be achieved within Unity, but it’s also about learning Blender.

I think I understand what’s happening. When you “apply” position/rotation/scale you basically “bake” these into the vertex-coordinates. For simplicity let’s assume the barrel needs to be at Y=2 so it’s positioned correctly relative to the base (which is positioned at abs-origin).

  • If you position the barrel at Y=2, “apply position” and then export, and import in Unity, it is positioned nicely relative to the turret-base, but you can’t nicely rotate around its local origin (it will rotate around a pivot, basically the offset between the absolute-origin and the barrel-origin).
  • If you position the barrel at the absolute-origin, “apply position” and then export, you can rotate nicely, but in Unity you need an additional “Pivot-empty” at y=2 to position it correctly relative to the turret-base and in that Pivot-empty you have the “Barrel-graphic” in a child with y=0 (the recoil-animation then applies coordinates to this child’s position). So this works fine, but of course animating in Blender is impossible because all objects are overlapping in the origin.
  • If you position the barrel at the absolute-origin, “apply position”, then move it back in blender so the barrel looks correct relative to the turret-base, then in Unity it works as in case 2, except the animation. The animation still fetches your Y=2 position and uses that, even if you only used delta-positions to animate. Meaning when play play the animation it jumps “another +2” and it jumps back to the correct position when you exit the animator.

So the one workflow I found is to have your objects position where they need to be in the scene. Animated it using delta-position (so you can move things around without breaking the animation). Then to export, move everything into the absolute origin and bake (so your vertex data is not accidently "far away from the origin), then export it while it’s positioned there. And after exporting undo that so everything is back where it was and you can animate (instead of having a mess of objects overlapping in the origin).

Additional thoughts:

  • Maybe this works if you parent the barrel to the turret, but I think it’s still broken when you export ( animation it pops “up” in Unity).
  • Maybe this can be done with “armatures” and a 1-bone animation for every object you want to animate.
  • Probably easiest is a script which automates this process of “move to origin, export, revert”. I think I’ve seen such solutions when googling for this issue, makes you wonder why this is not a checkbox in the original fbx exporter (maybe there are better workflows which avoid this entirely?).
  • Wondering if it’s possible to specify an “Root for animation” to avoid requiring the animator to be in the “Vertical” pivot, instead of directly in the “Turret_X1_Canon” (=barrel) together with the mesh. Probably happening because of the WSP.002 in Blender something to look into more closely)

Keep in mind, non graphics artist, so there are probably much better ways to achieve this. Happy to hear advice from the Blender experts out there what the correct way of doing this is. :slight_smile:

I Cannot help you with blender FBX exporter, I myself got problems for years with it.
But I would like to suggest dropping animation for this simple object and do turret movement programmatically.

While that is probably the most sensible approach for this specific case, that would not teach me anything about blender. (nor would it help anyone looking at all the similar, unanswered posts I found).

My goal was to gain some basic understanding of the workflow, to at least be able to correctly export models (avoid position/scale issues between Blender and Unity) and glance over the topic of animations. I specifically picked this case because it was the easiest example to try, and while the solution I found above is probably not the best, it a way to do it. In the end I might indeed end up doing this case programmatically, but at least with a rough idea of the alternative.

Blender and FBX have always been full of surprises, especially when it comes to rotation and animation. My solution has been to switch to another format, glTF. So far everything has been working flawlessly.

Here’s a quick experiment you can try: Export your scene to glTF (.glb) and drag/drop the file into an online viewer like this one https://gltf-viewer.donmccurdy.com/
If the model/animation loads correctly there, it’s a problem with the FBX exporter, not your workflow.