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

PLEASE allow us to pass MANAGED types to jobs !

Discussion in 'Entity Component System' started by genaray, Mar 27, 2022.

  1. genaray

    genaray

    Joined:
    Feb 8, 2017
    Posts:
    191
    I mostly use jobs together with the entities package. And i often run into cases where i wanna acess managed classes from within jobs. Sometimes from within multithreaded jobs, but mostly from single threaded jobs ( IJobEntityBatch... ).

    However, this is NOT possible. I can understand that the devs permit managed types in scheduled or parallel jobs... however i can NOT understand why this is the case for jobs being executed on the mainthread.

    Furthermore it should be our responsibility, those restrictions feel like some sort of child security system. But most of us have enough experience to know what to do and when it makes sense to acess managed types or when it may create race conditions. We arent children anymore. Of course burst also plays a roll here, but not everyone uses burst aswell.

    Of course we can pin managed types and pass their pointer to our jobs, but this is additional work and doesnt always work ( looking at you generic delegates ! ).

    It would be great if there would be some sort of attribute, tag or whatever to allow jobs to contain managed types directly. Give us back our responsibility !
     
    chadfranklin47 likes this.
  2. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,008
    I wonder how IL2Cpp would work with this.
     
  3. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    296
    I haven't use jobs much, but what is the advantage of non-burst main thread job over executing the code directly?
     
    Junkface and davenirline like this.
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    You can use GCHandle for situations where access to managed objects is truly necessary.
    Generally speaking it is very much not how we recommend using the job system.
     
  5. apkdev

    apkdev

    Joined:
    Dec 12, 2015
    Posts:
    263
    Last edited: Mar 27, 2022
    tmonestudio and bb8_1 like this.