Skip to main content

Unmanaged Animation Curve

Unity provides animation curves with the AnimationCurve class. Unfortunately as of now this is a class and so cannot be used inside burst compiled jobs. AnimationCurveUnmanaged can be used to bypass this restriction. The following snippet shows using AnimationCurveUnmanaged inside a implementation of a simple behavior.

Sample usage of AnimationCurveUnmanaged
[BurstCompile]
struct SampleJob : ISimpleBehaviorJob<SampleComponent, VelocityResult>
{
public AnimationCurveUnmanaged Curve;

public VelocityResult Execute(EntityInformation<SampleComponent> entity)
{
float x = Curve.Sample(0.1f);
...
return result;
}
}

public class SampleJobWrapper : ISimpleBehaviorJobWrapper
{
[SerializeField] private AnimationCurve animationCurve;

public JobHandle Schedule(...)
{
AnimationCurveUnmanaged curve = new AnimationCurveUnmanaged(animationCurve, 100);

var outDependency = new SampleJob
{
Curve = curve
}.Schedule<SampleJob, SampleComponent, VelocityResult>(...);

curve.Dispose(outDependency);
return outDependency;
}
}