Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Error with IJobForEach

Discussion in 'Entity Component System' started by PJRM, May 2, 2019.

  1. PJRM

    PJRM

    Joined:
    Mar 4, 2013
    Posts:
    303
    So, i have this script:
    Code (CSharp):
    1. namespace Game.Systems {
    2.    using Unity.Entities;
    3.    using Unity.Burst;
    4.    using Game.Data;
    5.    using Unity.Jobs;
    6.    using UnityEngine;
    7.  
    8.    public class InputSystem : JobComponentSystem {
    9.       [BurstCompile]
    10.       struct InputJob : IJobForEach<InputData> {
    11.          public float horizontalAxis;
    12.          public float verticalAxis;
    13.  
    14.          public void Execute(ref InputData inputData) {
    15.             inputData.Horizontal = horizontalAxis;
    16.             inputData.Vertical = verticalAxis;
    17.          }
    18.       }
    19.  
    20.       protected override JobHandle OnUpdate(JobHandle inputDeps) {
    21.          InputJob job = new InputJob() {
    22.             horizontalAxis = Input.GetAxis("Horizontal"),
    23.             verticalAxis = Input.GetAxis("Vertical")
    24.          };
    25.  
    26.          return job.Schedule(this, inputDeps);
    27.       }
    28.    }
    29. }
    and i'm receiving this error:
    upload_2019-5-1_22-15-46.png
    when i remove the interface the error goes away, so i don't know what to do.
    Is this an error in this interface or am i doing something wrong?

    I followed the example in https://docs.unity3d.com/Packages/com.unity.entities@0.0/manual/entity_iteration_job.html
     
  2. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    InputData needs to be a struct instead of a class. In addition, the InputData struct cannot have unmanaged fields.
     
  3. PJRM

    PJRM

    Joined:
    Mar 4, 2013
    Posts:
    303
    thank you. i feel ashame of finding github and finding that InputData needs to be IComponentData.

    Thank you for reply.
     
  4. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    335
    No shame in making mistakes mate.
     
    PJRM likes this.