Search Unity

What is #if ENABLE_BURST_AOT directive?

Discussion in 'Entity Component System' started by Antypodish, Sep 7, 2021.

  1. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,782
    What
    Code (CSharp):
    1. #if ENABLE_BURST_AOT
    does?
    Does it checks, if burst is enabled? What AOT stands for?
    How I could use #if directive, to check if burst is enabled, or not?
     
  2. Mockarutan

    Mockarutan

    Joined:
    May 22, 2011
    Posts:
    159
    I'm not sure exactly how it works with burst, but AOT stands for Ahead Of Time. So presumably it decides whether the burst compiler compiles everything straight away or if it waits until the execution is trying to invoke the code.
     
    Antypodish likes this.
  3. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    529
    I don't think you can. The code is compiled by the C# compiler which has no information about burst. After compilation nothing is left of
    #if
    . Activating/deactivating burst does not trigger a recompile.

    I don't know if this actually is your problem: One way to branch based on burst is using
    BurstDiscard
    with a
    ref
    attribute.
    Code (CSharp):
    1.     void DoSomething()
    2.     {
    3.         var isUsingBurst = true;
    4.         CheckBurst(ref isUsingBurst);
    5.  
    6.         if (isUsingBurst)
    7.         {
    8.             // burst
    9.         }
    10.         else
    11.         {
    12.             // non burst
    13.         }
    14.     }
    15.  
    16.     [BurstDiscard]
    17.     static void CheckBurst(ref bool isUsingBurst)
    18.     {
    19.         isUsingBurst = false;
    20.     }
    21.  
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,782
    Interesting,
    We use already [BurstDiscard] on our doggy method, which is used for debugging, but somehow doesn't resolve our issue.
    We try to track, where the issue is coming from.
    And technically should work.

    Interesting x2
    @Mockarutan thx for AOT explanation.
    Somehow, #if ENABLE_BURST_AOT seems skips / resolves the issue of the doggy method. But on other hand, I don't want to use it, if not understanding, what is exactly doing, even if we used for debugging only.

    Thx guys with responses so far.