I am using AnimationCurve not for animation but for calculations. It is a class so it could not go inside a job, moreover even if it can, this message would show up :
Evaluate can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
UnityEngine.AnimationCurve:Evaluate(AnimationCurve, Single)
FormationSt:LerpFormation(FormationSt, FormationSt, Single, Boolean) (at Assets/Scripts/Gameplay/Gameplay/FormationSt.cs:139)
Job:Execute() (at Assets/Scripts/Gameplay/Gameplay/System/GameplayLayoutSystem.cs:207)
Unity.Jobs.JobStruct`1:Execute(Job&, IntPtr, IntPtr, JobRanges&, Int32) (at /Users/builduser/buildslave/unity/build/Runtime/Jobs/Managed/IJob.cs:30)
Unity.Jobs.JobHandle:ScheduleBatchedJobsAndComplete(JobHandle&)
Unity.Jobs.JobHandle:Complete() (at /Users/builduser/buildslave/unity/build/Runtime/Jobs/ScriptBindings/JobHandle.bindings.cs:20)
However animationCurve.keys inside are already pure struct that would do well in a class/ECS. Is there any way that I can evaluate those keys in the job? Any algorithm that I have to rewrite in a job is fine too but I don’t know the terms to search for. A keyframe contains :
float m_Time;
float m_Value;
float m_InTangent;
float m_OutTangent;
int m_TangentMode;
int m_WeightedMode;
float m_InWeight;
float m_OutWeight;
Looking into CsReference the code already says thread safe so actually there might be a chance that Unity can already do this?
Also just an idea, in the docs I understand why a job could not spawn an another job well. But what if a job could ask for the main thread to perform a task for it? Then we can access all of main thread-only methods in the middle of the job. (Not an expert in concurrency so I don’t know what kind of problem would arise if we allow this)






