Can I set an AnimationCurve keyframe's interpolation to Constant at runtime?

I want to create an AnimationCurve at runtime and set it to Constant interpolation, i.e. so the curve looks like a flight of stairs. I can’t see any methods or properties to do this, so I’m wondering if it’s only doable in the curve editor?

I know I can use the InTangent and OutTangent of a keyframe, but that would not set interpolation to constant…

You just need to set the tangent to “float.PositiveInfinity” since the tangent holds the tan(angle). You want an angle of 90° so tan(90) == infinity

Just realised what you mean by “constant”. You have to recalculate the tangents manually. The Animation curve always uses a curve. Take a look at the “Linear” helper function:

// C#
public static AnimationCurve Linear(float timeStart, float valueStart, float timeEnd, float valueEnd)
	float num = (valueEnd - valueStart) / (timeEnd - timeStart);
	Keyframe[] keys = new Keyframe[]
		new Keyframe(timeStart, valueStart, 0f, num),
		new Keyframe(timeEnd, valueEnd, num, 0f)
	return new AnimationCurve(keys);

Indeed setting the tangent to infinity (I guess float.NegativeInfinity rather) , gives constant interpolation.
However if you want a curve editor for runtime ,check this out : Runtime Curve Editor | GUI Tools | Unity Asset Store