Orienting bones to Y forward

So I have a simple mesh made in blender, with two bones. When I import this into unity, the rotations are corrected for the model, but the bones are another story.

Each bone always has its local forward direction set to X (for any model I import), while the rest of the model is correct. I need to be able to manipulate this bone in code (it will not be used for any sort of animation), and it is causing me grief.

My goal is to have an attached script reference the bone, and make it point in the direction of a normal from elsewhere in my game. The rotation is never correct though, and usually WILDLY incorrect.

I know that the most likely culprit is the X axis being forward for the bone. So what I am wondering is two things:

  1. Is there a way to get this exported from blender such that the model, armature, and bones all have the same forward vector?
  2. If not, what could I do in my script to transform the bone such that Y is the forward axis; without actually moving the bone (as this would move the mesh)

Here aer some code snippets I had tried:

GameObject go = GameObject.Instantiate(prefabSegment);
                    Transform start = go.transform.FindChild("Skeleton/Segment_Start").transform;
                    Transform end = go.transform.FindChild("Skeleton/Segment_Start/Segment_End").transform;                    

                    start.position = splineSeg.Value.position;
                    start.rotation = Quaternion.FromToRotation(start.forward, splineSeg.Value.direction);

And

Quaternion.LookRotation(splineSeg.Value.direction)

btw, splineSeg is a LinkedListNode containing some information from a portion of a bezier curve; so “.direction” is the normal I want to use as the direction to face the bone in. prefabSegment is the imported mesh

It is also worth noting that the setting of position is absolutely correct; the issue lays with rotation (be it code bugs, export issues, or both).

I am at a loss here.

It’s a common problem and one that doesn’t have a neat solution. What you can do is:

  1. Temporarily create an empty gameobject at the bone’s position with the desired rotation, make it a parent of the bone, and rotate it, then unparent it and destroy it.
  2. Apply the rotation to the bone (in LateUpdate()), and also apply a rotation offset vector to it’s rotation. For example, you apply Transform.LookAt first, and then use Transform.Rotate.