Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Odd rotations on import

Discussion in 'Asset Importing & Exporting' started by MikeUpchat, Jul 4, 2015.

  1. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,055
    Hi There
    I am having trouble with FBX importing, I have a very simple scene in Max with a cube, a light and a camera, I export to fbx then import that into Unity, I then add a light component to the light object and a camera component to the camera obj in the scene. The problem is the objects are pointing in the wrong directions, the cube object is fine but the others are wrong, why does Unity get the rotations wrong for the two non mesh objects. Note this is not the usual, my object has a -90 degree x rotation as I dont care about that, I just need the objects to be pointing in the correct directions relative it each other. Can anyone shed any light on why this is happening and is there any way to fix it? Below is a grab from Max and one from Unity showing the camera and light having totally wrong rotations. Also attached the Max scene and fbx so you can see the problem.
    Mike
    fbx2.jpg fbx1.jpg
     

    Attached Files:

    Last edited: Jul 4, 2015
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Looks like the usual -90 degree x rotation to me.
    Recreate the camera and light in the front vireport - then export. See if that resolves the problem.
     
  3. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,055
    Thanks for the help but the rotations are totally off, the camera has a small twist on the z axis for a start, and if it were just that all the objects had the extra -90 degree x rotation then they would still be pointing in the right directions relative to one another, but the light is pointing down instead of at the cube and again the camera should be pointing at the cube but is pointing 90 degress away and with a twist. As I said I dont mind that Unity adds extra rotations but why is it any mesh object is fine but any helper object such as lights, cameras etc end up wrong?
     
  4. Pix10

    Pix10

    Joined:
    Jul 21, 2012
    Posts:
    850
    Rather than adding components to the imported camera & light nodes, parent a new light and camera to the respective gameobjects. This will make it a *lot* easier to re-orient them.

    Once oriented you can also drag them out of the tree back to the hierarchy root, and they'll retain their modified orientation (worth bearing in mind in case that becomes useful in the future).

    See the attached: box, camera and light from Max imported to Unity.
     

    Attached Files:

    theANMATOR2b likes this.
  5. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,055
    Thanks Pix10 but that is not what I need, I need the helper objects exported from Max to be pointing in the right direction without having to go through and manually add new objects and make parents and try and hand match the rotations. The issue is why does Unity not have correct rotations for non mesh objects. For example the local rotation of the camera in the fbx file is:
    Code (csharp):
    1. P: "Lcl Rotation", "Lcl Rotation", "", "A",113.993125580551,-0,-179.999991348578
    But Unity turns that into:
    Code (csharp):
    1. -1.5258 -90 -66.006
    If I hand convert the value using the process Unity uses for the mesh objects I get
    Code (csharp):
    1. -66 180 0
    Which is correct, so what is it that Unity does differently and how can it be persuaded to do it correctly?
     
  6. Pix10

    Pix10

    Joined:
    Jul 21, 2012
    Posts:
    850
    It doesn't just do this for cameras and lights, it does it for all objects. Try rotating a cube around x and z and exporting that, you'll see the same result. An object with clean rotation in one axis isn't going to demonstrate it.

    This time exporting a cube from Maya...

    FBX:
    P: "Lcl Rotation", "Lcl Rotation", "", "A",-33.5906495470011,-43.0289991530066,35.3048963861764
    (same as in Maya)

    Unity:
    -7.065, 52.149, -25

    The numbers aren't wrong, they're just the result of the co-ordinate system conversion. Try aligning an arrow geo to your camera, they'll have the same orientation in Unity. The camera orientation is fine.

    But that's not the problem anyway; IIRC it's that the camera and Light components are aligned to different axis in Unity (Forward), and that conversion isn't carried over because Unity doesn't properly support importing cameras and lights - it imports them as nulls and washes it's hands of it. (I might even be wrong about this in recent versions, but it's what I concluded donkeys ago after going through the same faff...I've just lived with it and worked around it ever since).

    You get more surprised if you mix regular and physical cameras (from Max), as they'll point in different directions too.
     
    Last edited: Jul 5, 2015
    theANMATOR2b likes this.
  7. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,055
    Yes I see your point, but surely if it does it for all objects in a max file they should all point in the same direction relative to one another as they do in the Max scene but they don't the cameras and lights point in totally different directions as can be seen if you try the max and fbx files I attached to the first point, and my question is still why? If every object under goes the same coordinate change why is it the mesh objects end up correct but the light and camera objects are wrong? If as you say Unity decides to not bother doing correct import of objects if they are not meshes then that is surely a an issue that needs to be fixed.
     
    Last edited: Jul 5, 2015
  8. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    I defer to more knowledgeable people for 'why' that happens. Pix10 seems to know - and his explaination sounds logical.

    A solution could be to align mesh objects to the camera and light in max then use them as non renderable orientation objects in Unity.
     
  9. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,055
    I dont understand why though, why should Unity treat non mesh objects differently? Why not just apply the same rules so objects are aligned as expected, surely it is just a bug as it not expected behaviour, isn't it fundamental to expect a game engine to import objects in a consistent manner? Would love to hear from someone at Unity as to why this happens? For my project it is key that I can export 100's of helper objects that are correctly aligned, it will just be impossible to manually go through and align them by hand or add mesh objects in Max that would then need to be deleted by hand again in Unity.
     
  10. Pix10

    Pix10

    Joined:
    Jul 21, 2012
    Posts:
    850
    Heplers (nulls) are exported the same as regular geometry, as I point out above - create a cube, create some helpers (a Dummy, a Container, say) and use the align tool to match them to your cube. Their transform will match in Unity.

    The key thing is the Forward vector, and yes, Unity screws it up - but only on Camera and Lights.

    As I first suggested, you can either add cameras/lights to the nulls unity is importing (do it through a script/post-process and re-orient them in one pass), or you can import actual nulls in place of the camera/light (use Bone On in Bone Tools to force the FBX exporter to export them as joint helpers/nulls/dummies), preventing Unity from messing with the axis conversion. Then you just have to rotate the transform 180° on it's local Y axis (afraid you can't get around the additional axis flip, that's Unity components Forward vector).
     
    theANMATOR2b likes this.
  11. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,055
    Thanks again, I can likely find a workaround though it is not ideal, what I really can't understand though is why Unity just cant import the objects correctly, I have tried the same file in Unreal and 2 other game engines and their FBX importer handles them no problem and everything points in the right direction, I find it amazing that Unity has such a bug in the key FBX importer and that it hasn't been fixed.
     
    a_p_u_r_o likes this.
  12. Prashanthbv

    Prashanthbv

    Joined:
    May 7, 2015
    Posts:
    4
    Were you guys ever able to find a solution for this? I am having the same issue and it is so annoying. So tough to understand the axis policy in unity
     
  13. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    I have not experienced this issue - though I don't import lights and cameras.
    A guess - could the lights/cameras be aligned to and attached or parented to a dummy/point helper - to overcome the issue?

    I've used dummies/points as joint angle effectors in character rigs and they were oriented correctly upon import into Unity.