Below is my code, and I do not know what to do with the errors
public class TestFinal : MonoBehaviour
{
[SerializeField] private Mesh mesh;
[SerializeField] private Material material;
public Texture2D _imageMap;
[SerializeField] private bool useJobs;
private NativeArray<Entity> entityArray;
//public peerAtAudio Audiopeer;
public int startScale;
public int startMultiplier;
public EntityManager entityManager;
public EntityArchetype entityArchetype;
public NativeArray<Entity> entityArray1;
private void Start()
{
entityArchetype = entityManager.CreateArchetype(typeof(Translation), typeof(_bandComp), typeof(RenderMesh), typeof(LocalToWorld), typeof(Transform)); //entity that contains these
entityArray1 = new NativeArray<Entity>(_imageMap.width * _imageMap.height, Allocator.Temp);//Allocator.Temp is chossen temp will be temporary to just establish the 2 entities
Color[] pixels = _imageMap.GetPixels(0, 0, _imageMap.width, _imageMap.height);
entityManager = World.Active.EntityManager;
entityManager.CreateEntity(entityArchetype, entityArray1); //create entity in entity manager
int i = 0;
for (int x = 0; x < _imageMap.width - 1; x++)
{
int iter = x * _imageMap.width;
for (int y = 0; y < _imageMap.height - 1; y++)
{
Color color1 = pixels[(iter) + y];
Entity entity = entityArray1*; //put each entity in the NativeArray*
entityManager.SetComponentData(entity, new Translation
{
Value = new float3(x, 0, y)
});
entityManager.SetComponentData(entity, new _bandComp
{
_band = UnityEngine.Random.Range(0, 8)
});
Material mat = new Material(material);
mat.color = color1;
entityManager.SetSharedComponentData(entity, new RenderMesh
{
mesh = mesh,
material = mat
});
i++;
}
i++;
}
}
private void Update()
{
int size = _imageMap.width * _imageMap.height;
ReallyToughParallelJob reallyToughParallelJob = new ReallyToughParallelJob
{ deltaTime = Time.deltaTime, entityMang = entityManager, entityArr = entityArray1 };
JobHandle jobHandle = reallyToughParallelJob.Schedule(size, 100); // 100 means each job is handeling 100 components
jobHandle.Complete();
/* ReallyToughParallelJob reallyToughParallelJob = new ReallyToughParallelJob { }
float startTime = Time.realtimeSinceStartup;
NativeArray positionArray = new NativeArray(cubezList.Count, Allocator.TempJob);// in a regular game you will not need to instantiate this every time
NativeArray moveYArray = new NativeArray(cubezList.Count, Allocator.TempJob);
for (int i = 0; i < cubezList.Count; i++)
{
positionArray = cubezList*.transform.position;*
moveYArray = cubezList*.moveY;*
}
ReallyToughParallelJob reallyToughParallelJob = new ReallyToughParallelJob
{ deltaTime = Time.deltaTime, positionArr = positionArray, moveYArr = moveYArray };
JobHandle jobHandle = reallyToughParallelJob.Schedule(cubezList.Count, 100); // 100 means each job is handeling 100 components
jobHandle.Complete();
for (int i = 0; i < cubezList.Count; i++)
{
cubezList_.transform.position = positionArray*;
cubezList.moveY = moveYArray;
}
positionArray.Dispose();
moveYArray.Dispose();
/
}_
[BurstCompile]
public struct ReallyToughParallelJob : IJobParallelFor
{
public NativeArray entityArr;
public EntityManager entityMang;
public float deltaTime;
public void Execute(int index)//index for multiple objects
{
Entity entity = entityArr[index];
float3 val = entityMang.GetComponentData(entity).Value;
float3 val2 = new float3(1 * deltaTime, 0, 0);
val = val + val2;
entityMang.SetComponentData(entity, new Translation
{
Value = val
});
}
}
}
I get these two errors:
------------------------------------------------------------------------------------------------------------------------------------------------------
NullReferenceException: Object reference not set to an instance of an object
TestFinal.Start () (at Assets/tutorial/TestFinal.cs:34)
------------------------------------------------------------------------------------------------------------------------------------------------------
InvalidOperationException: ReallyToughParallelJob.entityMang is not a value type. Job structs may not contain any reference types.
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.IJobParallelForExtensions+ParallelForJobStruct`1[T].Initialize () (at C:/buildslave/unity/build/Runtime/Jobs/Managed/IJobParallelFor.cs:23)
Unity.Jobs.IJobParallelForExtensions.Schedule[T] (T jobData, System.Int32 arrayLength, System.Int32 innerloopBatchCount, Unity.Jobs.JobHandle dependsOn) (at C:/buildslave/unity/build/Runtime/Jobs/Managed/IJobParallelFor.cs:50)
TestFinal.Update () (at Assets/tutorial/TestFinal.cs:81)
------------------------------------------------------------------------------------------------------------------------------------------------