How to force IJobEntity to execute on MainThread?
Unity 2022.3.1f1
Entities 1.0.16
How to force IJobEntity to execute on MainThread?
Unity 2022.3.1f1
Entities 1.0.16
The problem is that InputAimJob is executed on WorkerThread unless I add a managed component when it will be executed on MainThread. How do I force IJobEntity to the MainThread without using a managed component?
public partial struct InputAimJob : IJobEntity
{
public void Execute(ref CannonAimValue aimValue)
{
var hor = Input.GetKey(KeyCode.LeftArrow) ? -1 : Input.GetKey(KeyCode.RightArrow) ? 1 : 0;
aimValue.HorizontalAim += 1 * hor;
var ver = Input.GetKey(KeyCode.UpArrow) ? 1 : Input.GetKey(KeyCode.DownArrow) ? -1 : 0;
aimValue.VerticalAim += 1 * ver;
}
}
public partial struct InputAimJobTest : IJobEntity
{
public void Execute(ref CannonAimValue aimValue, EntityGameObject entityGameObject)
{
var hor = Input.GetKey(KeyCode.LeftArrow) ? -1 : Input.GetKey(KeyCode.RightArrow) ? 1 : 0;
aimValue.HorizontalAim += 1 * hor;
var ver = Input.GetKey(KeyCode.UpArrow) ? 1 : Input.GetKey(KeyCode.DownArrow) ? -1 : 0;
aimValue.VerticalAim += 1 * ver;
}
}
You can’t use non-threadsafe UnityEngine APIs in jobs even if you run the job on the main thread. You should read input in the system directly.
I get it, I need RunByRefWithoutJobs, but it’s internal. No UnityAPI in Jobs for me