Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Can a Burst Job use any managed types?

Discussion in 'Data Oriented Technology Stack' started by orionburcham, Jan 15, 2019.

  1. orionburcham

    orionburcham

    Joined:
    Jan 31, 2010
    Posts:
    491
    Hi. I understand that a Burst-compiled Job should only contain blittable members. But can its Execute() method involve *any* managed types?

    For example, would this be valid?


    Code (CSharp):
    1. [BurstCompile]
    2. struct MyJob : IJobChunk
    3. {
    4.     public void Execute(ArchetypeChunk chunk, int chunkIndex)
    5.     {
    6.         ComponentType componentType = typeof(MyComponent);
    7.     }
    8. }
    Please notice the "typeof()" call, which will return a (managed) System.Type instance.

    I understand it would be easy to avoid making this call in the example. But I'm wondering if the typeof() call, as written, would break Burst compilation.

    Thanks!
     
    Last edited: Jan 15, 2019
  2. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    611
    Nope. for your example, you can have a ComponentType field and assign it when you setup the Job struct on the main thread. The no-managed restriction applies to both members and method bodies. If you're job struct calls any utility functions, they also must not contain any managed code access.

    So the pure functional Unity.Mathematics calls work, and calling methods on pure blittable non-job structs will also work as long as no managed types are accessed.
     
    orionburcham likes this.