Search Unity

Method inside Execute()

Discussion in 'Entity Component System' started by RoughSpaghetti3211, Jun 15, 2019.

  1. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,708
    I was wondering why I don’t see anyone use methods inside Execute().
     
  2. RecursiveEclipse

    RecursiveEclipse

    Joined:
    Sep 6, 2018
    Posts:
    298
    (I'm assuming you're talking about nested functions here)
    If there is no technical reason(like burst not liking it, I haven't tried it yet), then I'd assume it's because it's a new-ish feature and most people aren't aware it's now possible with C# 7. Or they just think it's bad practice or not necessary in most cases.

    On the other hand, if you're just talking about having other methods in the job struct that you call from Execute(), if it makes your code any nicer/more readable then I don't see why not.
     
    Last edited: Jun 15, 2019
    RoughSpaghetti3211 likes this.
  3. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    I used methods inside my Execute including local function feature from C#7. It works great and got inlined in the asm.
     
    RecursiveEclipse likes this.
  4. 8bitgoose

    8bitgoose

    Joined:
    Dec 28, 2014
    Posts:
    448
    Can someone point me to what you are talking about with C# 7? I use static methods inside Execute() all the time. Burst will compile it great too.
     
  5. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
  6. 8bitgoose

    8bitgoose

    Joined:
    Dec 28, 2014
    Posts:
    448
    @eizenhorn Oh nice, I had no idea. That seems like it may get confusing though....
     
  7. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    I pile up the methods at the bottom. When you do this enough it feels like you could turn the code into an entirely english sentence. I think it is best if you could define local function as exp. bodied => one liner so it doesn't look as unwieldly, and also great for recursion.
     
  8. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,708
    Do you have a code snippet, I’m curious :)