Hello,
I am trying to use unity’s fbx exporter to export fbx files from my runtime animation app.
The animation in the app is custom made(ie, it doesn’t use Unity’s AnimationClips or AnimationCurves). It just has transforms saved for each frame in a list. During playback, the transforms are applied on to the model at a set rate and it plays out like animations.
I am using Unity’s Fbx Exporter from the package manager. I am able to export the hierarchy and the meshes properly into the fbx file. The problem comes when I try to create the animation.
From the fbx sdk documentation, and unity’s fbxexporter script(com.unity.formats.fbx/com.unity.formats.fbx/Editor/FbxExporter.cs at master · Unity-Technologies/com.unity.formats.fbx · GitHub), I figured out I have to do this to create animation data in the fbx file
FbxAnimCurve rotationCurveX = thisNode.LclRotation.GetCurve(animLayer, "RotationX", Globals.FBXSDK_CURVENODE_COMPONENT_X, true);
rotationCurveX.KeyModifyBegin();
But this throws a null reference exception at KeyModifyBegin(), which means that the rotationCurveX is null.
According to the documentation, the true value in the GetCurve function is supposed to create the curve if it can’t find it.
It also says that the eAnimatable flag has to be true for it to work. So I added this before calling GetCurve.
thisNode.LclRotation.ModifyFlag(FbxPropertyFlags.EFlags.eAnimatable, true);
Even then, it still throws the null reference exception. I tried to put it inside a coroutine to try and delay the function, and even that didn’t help.
Any idea on what is happening and how I can fix it?
Edit: I have found it. When I was creating the AnimStack and AnimLayer, I was using the fbxManager, and not the fbxScene. Now the error is gone.
I still need the animations to appear in other software that imports fbx files.