How can I set all of my animation keyframes tangents to become right angles?

When importing animation data from my FBX I lose right angled tangent properties for my keyframes, how can I reset them in an automated process?

You can write an editor script to set all inTangent and outTangent properties of each keyframe to Mathf.Infinity.

To get access to the keyframes you can use AnimationUtility.GetAllCurves to read the values

Here is an example that creates an animation curve with all keyframes’ inTangent and outTangent properties set to Mathf.Infinity:

var anim : AnimationCurve = new AnimationCurve();
function Start() {
var ks : Keyframe[] = new Keyframe[3];
	ks[0] = Keyframe(0, 0);
	ks[0].inTangent = Mathf.Infinity;
	ks[0].outTangent = Mathf.Infinity;
	ks[0].value = 0;
	ks[1] = Keyframe(4, 0);
	ks[1].inTangent = Mathf.Infinity;
	ks[1].value = 1;
	ks[2] = Keyframe(8, 0);
	ks[2].inTangent = Mathf.Infinity;
	ks[2].value = 0;
	anim = AnimationCurve(ks);
}

You could write this as an AssetPostprocessor to apply to the model on import

After some trial and error, I finally got this working and it looks great, thanks so much OllyNicholson.

Only issue if you have the animation window open it hangs while there are tons of errors spitting out.

Anyone have any ideas how this can be fixed?

Quaternion To Matrix conversion failed because input Quaternion is invalid {-1.#IND00, -1.#IND00, -1.#IND00, -1.#IND00} l=-1.#IND00
UnityEditor.AnimationUtility:GetCurveBindings(AnimationClip)
UnityEditorInternal.AnimationWindowState:get_allCurves() (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/Animation/AnimationWindow/AnimationWindowState.cs:237)
UnityEditorInternal.AnimationWindowHierarchyDataSource:FetchData() (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/Animation/AnimationWindow/AnimationWindowHierarchyDataSource.cs:42)
UnityEditor.TreeView:ReloadData()
UnityEditorInternal.AnimationWindowHierarchyDataSource:UpdateData() (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/Animation/AnimationWindow/AnimationWindowHierarchyDataSource.cs:126)
UnityEditorInternal.AnimationWindowState:Refresh() (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/Animation/AnimationWindow/AnimationWindowState.cs:525)
UnityEditorInternal.AnimationWindowState:OnGUI() (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/Animation/AnimationWindow/AnimationWindowState.cs:70)
UnityEditor.DockArea:OnGUI()