Unity: recursion or not recursion?

Hi everyone. My questions is more theoretic than real, but I’d like to create the right mindset to improve my unity skills.

The reason of the question is:

I haven’t seen any recursive method in unity yet. I’m using third party code and other code I found on the web. I’ve also followed quite a few tutorials, but yet no recursion.

The question is:

Can anyone explain me why there is so few recursion in Unity?
Maybe it’s just me and I’ve not yet worked on advanced code. Or maybe it’s because of unity logic.
I just like to know if I should or should not implement recursion in Unity.

As others have said, the fundamental nature of Unity3D (and all client based games) is a game loop.

Having said that, recursion can be very useful for certain types of problems inside of that loop, such as tree evaluation, and there is no inherent reason not to use it. Call overhead is pretty minimal in modern compiled code and there is no damage you can do to yourself with recursion that you cant do equally easily with nested loops.

Well, unity logic is one thing … Don’t forget recursive processes are complex and expensive on your executable code. The recursive and tail recursive algorithms in theory are more calculative and continuous process which depends on its previous outputs and inputs until base conditions are reached.

For the purposes of a game engine like unity there really is no particular necessity of an inbuilt recursive method or interface. Furthermore most inbuilt frame dependent methods like update etc… Are frame dependent unless you are using your own custom classes or functions. The philosophy of per frame calls in unity mono behavior scripts would further complicate and lead to catastrophic results also freezing your project execution if used carelessly. And as you would realize most inbuilt methods and functions in unity are implemented usually as frame dependent methods.

Though if you need to play with concepts like tail recursion and Fibonacci which are ideal and specific to concepts of recursive calculations then you can always make custom classes and methods …
But just for the sake of using recursion it is not preferable to use a game engine like unity where object manipulation code is structured except if you have truly circumstantial reasons to use the calculations in a seperate class or to perform certain clearly defined code effects. Loops, frame updates and animations can do a lot more for you cheap than what recursive calculations can expensive as they are.

Red.