Best way to get data from a Monobheaviour in a JobComponentSystem?

protected override void OnCreate()
//gridArray is a reference to another Native Array created in a MonoBehaviour.
gridArray = GameObject.FindGameObjectWithTag(“Global”).GetComponent().experimentalGrid;


I’m trying to fetch a NativeArray that’s created in the main thread for use in a job. Unfortunately, not even this works. It doesn’t read gridArray as assigned or constructed. Now obviously this isn’t best ECS practice to begin with, but the inability to do something so simple is absolutely killing me.

InvalidOperationException: The NativeContainer MovementJob.Data.GridArray has not been assigned or constructed. All containers must be valid when scheduling a job.

What am I missing? Is there any convenient way to get data from Monobehaviours at all?

Are you sure NativeArray is constructed before OnCreate() runs on system. It might not exists like error says.

I had a similar problem and it seems like systems get executed before Monobehaviours, so either you can start yoor system in your monobehaviours manually, or you look if the native list is null, than you init it within the onCreate method for testing reasons. One idea (but i dont know if it works), is to use a wait coroutine in the on create funktion.