Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Oct 30, 2014 at 05:37 AM by Kiwasi for the following reason:

Question is off-topic or not relevant

avatar image
0
Question by Jack-Mariani · Oct 28, 2014 at 08:09 AM · c#recursion

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kiwasi · Oct 30, 2014 at 05:39 AM 0
Share

Discussion on program$$anonymous$$g paradimes is for the forums. Hang around here and you will see the occasional recursive script, where the problem warrants it.

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by Redeemer86 · Oct 28, 2014 at 08:33 AM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Redeemer86 · Oct 28, 2014 at 08:40 AM 0
Share

Also keep in $$anonymous$$d the Start, Awake, Update ... And various frame dependent methods are manipulatable to provide ways for patterns of execution to provide effects and effective calculations for desired effects.

Red

avatar image
3

Answer by Jeff-Kesselman · Oct 28, 2014 at 03:22 PM

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Habitablaba · Oct 28, 2014 at 05:31 PM 1
Share

Additionally, if you want to see examples of recursion in Unity, I would start looking for projects that are very AI or path-planning heavy.

avatar image Owen-Reynolds · Oct 28, 2014 at 05:37 PM 1
Share

Second that. Recursion in Unity works great for the usual things recursion is good for. I use some recursive functions in a lovely maze generator. And in all my "do X to parent and all children" utility functions (the same as the old SetActiveRecursively used to do.)

I think most game programs just tend to be too simple to need recursion, and most game programmers aren't comfortable with it (the same reason you rarely see inheritance.)

avatar image Redeemer86 · Oct 30, 2014 at 05:10 AM 0
Share

$$anonymous$$y answer was to emphasize on the point as I understood from your question , that there are no requirements for inbuilt recursive methods in unity or predefined unity functions ... Although if your implementation is justified you can customise your own functions to achieve specific recursive calls as side effects .

Red

Follow this Question

Answers Answers and Comments

30 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Unity and Custom Defines 1 Answer

Ref modifier 1 Answer

A node in a childnode? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges