- Home /
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<CreateWorld>().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?
Answer by GamerLordMat · Mar 10, 2020 at 06:03 PM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220612224430im_/https://answers.unity.com/themes/thub/images/avi.jpg)