Search Unity

JobHandle.IsCompleted defaults to true?

Discussion in 'Entity Component System' started by Nyanpas, Sep 3, 2020.

  1. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    I did a check to see what the default value of JobHandle.IsCompleted is for a job in Update() by printing out the value to a Debug.Log() and it returns
    true
    even if no job has been completed yet. Wouldn't it make more sense to have it start as
    false
    and then if a job is completed, return
    true
    , or am I misunderstanding here?
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    When a JobHandle.Complete() is called it is set to its default value. This results in very quick early outs. Thus if a job handle has not been scheduled (default) at all it counts as completed.
     
    Nyanpas and nyanpath like this.
  3. nyanpath

    nyanpath

    Joined:
    Feb 9, 2018
    Posts:
    77
    (Alt-account just because of inlogging issues/corporate equipment/etc..)

    So I "solved" it by checking for another bool as well
    scheduled && _job.IsCompleted
    but IMHO it would be "cleaner" if IsCompleted defaulted to
    false
    because then I would only need to use that.
     
    jamesnw likes this.
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Thats a reasonable way of doing it. The current behaviour works as intended.
     
    julian-moschuering likes this.