- Home /
Raycast from IAnimationJob.ProcessAnimation()
I'm trying to write an IAnimationJob struct that performs foot-fixup against terrain as part of a PlayableGraph. However, both Physics.Raycast() and RaycastCommand.ScheduleBatch() complain about not being on the main thread. What's the correct way to raycast from the PlayableGraph's thread? If not, is there a way to synchronize with the main thread?
For reference, here is the log from attempting to schedule a raycast job:
UnityException: CreateJobReflectionData 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.
Unity.Jobs.LowLevel.Unsafe.JobsUtility.CreateJobReflectionData (System.Type type, Unity.Jobs.LowLevel.Unsafe.JobType jobType, System.Object managedJobFunction0, System.Object managedJobFunction1, System.Object managedJobFunction2) (at C:/buildslave/unity/build/Runtime/Jobs/ScriptBindings/Jobs.bindings.cs:96)
Unity.Jobs.LowLevel.Unsafe.BatchQueryJobStruct`1[T].Initialize () (at C:/buildslave/unity/build/Runtime/Jobs/Managed/BatchQueries.cs:33)
UnityEngine.RaycastCommand.ScheduleBatch (Unity.Collections.NativeArray`1[T] commands, Unity.Collections.NativeArray`1[T] results, System.Int32 minCommandsPerJob, Unity.Jobs.JobHandle dependsOn) (at C:/buildslave/unity/build/Modules/Physics/ScriptBindings/QueryCommand.bindings.cs:33)
TwoBoneTerrainFixupJob.ProcessAnimation (UnityEngine.Experimental.Animations.AnimationStream stream) (at Assets/Scripts/Anim/TwoBoneIK.cs:167)
UnityEngine.Experimental.Animations.ProcessAnimationJobStruct`1[T].Execute (T& data, System.IntPtr animationStreamPtr, System.IntPtr methodIndex, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at C:/buildslave/unity/build/Modules/Animation/Managed/ProcessAnimationJobStruct.cs:49)
Point of clarification: the foot location that we're querying-from is coming from an AnimationStream input -- our job adjusts the incoming intermediate pose with ik -- so the position isn't known before the playable-graph kicks-off evaluation.
Your answer
Follow this Question
Related Questions
making a chair animate float and fall 0 Answers
Raycast with a mouse position! 1 Answer
how to make an animation that can take value from script ? 0 Answers
Play Animation several times 0 Answers
Elevator to load next scene 2 Answers