Hi, I have some jobs, which are similar & parameterless. So I want to put them into an array to schedule and then combine the dependency, instead of doing it one by one.
I try this, but the complier complain that: The type ‘Unity.Entities.JobForEachExtensions.IBaseJobForEach’ must be a non-nullable value type in order to use it as parameter ‘T’
using Unity.Jobs;
using static Unity.Entities.JobForEachExtensions;
public IBaseJobForEach[] Jobs = {new xJob(), new yJob()};
public JobHandle ScheduleJobs()
{
foreach (var job in Jobs)
{
new SleepConsiderJob().Schedule();
}
}
Storing a struct in an array typed as an interface will result in a boxing conversion, essentially wrapping it in a reference type. The extension method has no way of knowing that whats in there is actually a value type and the Schedule extension requires a value type.
Set the type of your array to the actual type of the job, not the IJob interface.