I'm getting this error: Code (CSharp): Unexpected exception Burst.Compiler.IL.CompilerException: Unexpected exception ---> Burst.Compiler.IL.CompilerException: Error while processing function `System.Void SampleSystem/Job::Execute(MyData&)` ---> Burst.Compiler.IL.CompilerException: Unexpected error while processing `IL_0019: box ComplexData args(IL_0018)` at \SampleSystem.cs(24,7) ---> System.NotSupportedException: Boxing a valuetype to a managed object is not supported by burst Is boxing not allow when using Burst? I've wrote a sample system to show this: Code (CSharp): using Unity.Burst; using Unity.Entities; using Unity.Jobs; public interface IComplexData { float ComplexFloat { get; } } struct ComplexData : IComplexData { public float Value; public float ComplexFloat => Value; } public struct MyData : IComponentData { public float Value; } public class SampleSystem : JobComponentSystem { [BurstCompile] struct Job : IJobProcessComponentData<MyData> { public void Execute(ref MyData data) { var complexData = new ComplexData { Value = data.Value }; DoSomethingWithData(complexData); } } protected override JobHandle OnUpdate(JobHandle inputDeps) { inputDeps = new Job().Schedule(this, inputDeps); return base.OnUpdate(inputDeps); } private static float DoSomethingWithData(IComplexData data) { return data.ComplexFloat * 100f; } } Thanks for the great job on ECS
boxing = wrapping value type with an object and storing it on the managed heap objects are not blittable and not supported by jobs and burst
Thanks for the clarification. Doing it like this solves it: Code (CSharp): using Unity.Burst; using Unity.Entities; using Unity.Jobs; public interface IComplexData { float ComplexFloat { get; } } struct ComplexData : IComplexData { public float Value; public float ComplexFloat => Value; } public struct MyData : IComponentData { public float Value; } public class SampleSystem : JobComponentSystem { [BurstCompile] struct Job : IJobProcessComponentData<MyData> { public void Execute(ref MyData data) { var complexData = new ComplexData { Value = data.Value }; DoSomethingWithData(complexData); } } protected override JobHandle OnUpdate(JobHandle inputDeps) { inputDeps = new Job().Schedule(this, inputDeps); return base.OnUpdate(inputDeps); } private static float DoSomethingWithData<T>(T data) where T : struct, IComplexData { return data.ComplexFloat * 100f; } }
Yes! That is the idea. The example is incomplete and it was only to show the error in the first place.
Yes, it is not allowed because they are involving a reference type (through an interface in your case) The correct way to solve it is as you did, by using generic methods with structs and interface constraints. It will make the call to the struct implementation completely inline-able and this is a lot more efficient than using interface calls.