Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Using IConvertGameObjectToEntity class in IJobForEach

Discussion in 'Entity Component System' started by DouglasPotesta, Jan 17, 2020.

  1. DouglasPotesta

    DouglasPotesta

    Joined:
    Nov 6, 2014
    Posts:
    109
    How would I use the following converted class with an IJobForEach? I understand I have to use a NonNullable type for the IJobForEach.
    This is a trivial example. I understand I can circumvent this issue with a struct that implements IComponentData. However that is not the solution I am looking for.
    I am specifically looking for a way to utilize data stored on IConvertGameObjectToEntity class inside a Job. If this is not possible, then that is okay.
    I am just looking to gain a greater understanding.

    Code (CSharp):
    1. using Unity.Entities;
    2. using UnityEngine;
    3.  
    4. [DisallowMultipleComponent]
    5. [RequiresEntityConversion]
    6. public class ExampleClass: MonoBehaviour, IConvertGameObjectToEntity
    7. {
    8.     public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    9.     {
    10.     }
    11. }

    Code (CSharp):
    1. using Unity.Burst;
    2. using Unity.Collections;
    3. using Unity.Entities;
    4. using Unity.Jobs;
    5.  
    6. public class NewSystem : JobComponentSystem
    7. {
    8.  
    9.     [BurstCompile]
    10.     struct NewSystemJob : IJobForEach<ExampleClass> //Obviously can not use this class, I need a non nullable type.
    11.     {
    12.         public void Execute(ref ExampleClass example)
    13.         {
    14.            
    15.         }
    16.     }
    17.    
    18.     protected override JobHandle OnUpdate(JobHandle inputDependencies)
    19.     {
    20.         var job = new NewSystemJob();
    21.         return job.Schedule(this, inputDependencies);
    22.     }
    23. }