0
$\begingroup$

I asked over at Unity Answers, however no one answered yet so I am hoping to receive answers here.

I have this Kitchen Counter I made in Blender where I have it set up where the cabinet doors opens for my game. When I open my doors manually in Unity, it works find. However when I open them through a script or an animation it doesn't rotate correctly.

I recorded some videos and I have a Blender file available. I want to know what the problem is so I can prevent it in the future. Anyways, the video should help anyone who seeks to share knowledge get all the information needed. If you need more information although, just ask.

Here is a video of trying to open it through a script. https://youtu.be/WTeIgeWAXc0

Here is a video of trying to animate it. https://youtu.be/px6mY4YGIPU

My Blender file. Hopefully you don't mind me using Google Drive as this is where I originally uploaded to. I exported it to FBX as well as I use the normal Blender file inside of the Unity assets, both share same results. If you didn't guess already, it's best if you have Unity when fully testing it, but if you already know the problem then don't hesitate to share. https://drive.google.com/file/d/14yVDs2qMRdAJVy_3rv5xx3FGopwWvVbx/view?usp=sharing

$\endgroup$

1 Answer 1

0
$\begingroup$

The first video is hard to see. From the second one, its looks like what you get wen in a gimbal lock situation. You can either go around it by baking your animation, or try to fix it by changing the object's rotation order/mode. But I don't know how that can be done in Unity.

Baking

In Blender, select what you want to bake, then you can open the search bar via F3 and search for the Bake Action operator:

search

Most of its settings are self-explanatory, make sure to bake the frame range you need, clear the constraints if you are baking a complex rig from which you need to export only its deform bones without outer influences. Save as a copy (so to not overwrite your original non-baked animation, which is easier to work with and modify) and export.

It is recommended to do this anytime you export any animation to begin with, because it allows to "hide" such issues.
Each software and format exchange have its own way of doing things, and here the biggest culprit is that Unity and Blender do not use the same coordinates system to begin with (Blender: +Zup +X left, Unity +Yup -Xdown).

Baking on every frame allows to "force" the animation you made in Blender to "remain as it looked in Blender" on every frame even after importing it elsewhere, instead of leaving most of your animation up to the software's interpolations which will be different from each other just because of how they work differently under the hood.

It will not make the issue go away, but it will allow you to ignore it most of the time when you animate in Blender and just want to export the result straight into Unity or anywhere else.

Changing the rotation mode

What are Euler Rotations in Blender? | How to Avoid Gimbal Lock (2021) - YouTube

In Blender, you can do it in the sidebar:

rotation mode

If exporting with a new rotation mode doesn't seem to work, it could be many things. From Blender's exporter who doesn't export that change, the exchange, to Unity's importer who ignores it. Look inside Unity, if you can change it there. It will at least remove the potential issues with exporting and importing. Otherwise, maybe some people on the Internet already figured out precisely which settings to use and what button to press specifically for that, but I don't.

If you do manage to find the right setting for the rotation mode and export/imports, do keep baking your animations. It might not have the rotation mode issues anymore (until you try a different animation that rotates in a way that inevitably gimbal locks that rotation mode), but you still may have other interpolation differences without baking.

$\endgroup$
3
  • $\begingroup$ Have you tried to change your rotation mode and export again? $\endgroup$
    – Lauloque
    Commented Feb 19, 2023 at 0:52
  • $\begingroup$ I did do that. Did you test it yourself in Unity to ensure what you are telling me is accurate? If not, I do recommend you do. It could even be a gimbal lock inside Unity and not Blender. $\endgroup$ Commented Feb 19, 2023 at 3:07
  • 1
    $\begingroup$ I do not have Unity, sorry. And BSE being a Q&A about Blender only, I will keep it to Blender. Actually, I don't even know why I bother about rotation order, people have been avoiding this kind of issues for decades just by baking their animations, I should have started with that. I edited my answer. $\endgroup$
    – Lauloque
    Commented Feb 20, 2023 at 6:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .