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 /
avatar image
3
Question by sabliao · Oct 07, 2011 at 01:36 AM · functioncontrolreturnbreak

Is there a way to break out of a function and return control to another script's function?

I want to make a check before I execute some code in a script because the checks I had beforehand might now (due to some elapsed time) not be true anymore. Is there a way for me, within that if statement check, to break from the script and return control to a function in another script?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
12
Best Answer

Answer by syclamoth · Oct 07, 2011 at 01:38 AM

To manually exit out of a function at any time, use the 'return' keyword. Even for void functions (functions with no explicit return type), it is possible to cancel execution like this!

Along with that, there are the 'break' and 'continue' keywords for controlling execution from within a loop- 'break' automatically skips to the end of the entire loop, and 'continue' skips to the end of that particular iteration.

Comment
Add comment · Show 7 · 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 sabliao · Oct 07, 2011 at 01:47 AM 0
Share

I'm about to leave for the day, but I'll be looking into this more tomorrow and see how that goes. Another part of my question was if you could return to a specific function ins$$anonymous$$d of just going back to wherever you left off. Thanks for your reply!

avatar image kevork · Oct 07, 2011 at 01:50 AM 1
Share

void FunctionYouWantToBreakOutOf() { if(someCondition) { SomeOtherFunction(); return; } // whatever else you want to do }

avatar image syclamoth · Oct 07, 2011 at 01:50 AM 0
Share

Ah now that's a bit more tricky. I would look at structuring your program such that you don't have to do that. What language are you using? I can probably help you more if you are using C#, since my knowledge of Javascript (Unityscript) doesn't cover some of the more advanced stuff. I'm pretty sure there's something like delegates in Unityscript, but I don't know how to use them.

avatar image sabliao · Oct 07, 2011 at 01:55 AM 0
Share

Unfortunately I'm using JavaScript because there seems to be more examples and documentation for it.

avatar image sabliao · Oct 07, 2011 at 01:56 AM 0
Share

Oh, kevork! I just saw your comment. I'll try that tomorrow as well. Thank you for the idea!

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to make camera position relative to a specific target. 1 Answer

Breaking out of a function from an if statement inside..... Noob 1 Answer

How to call a function on a prefab script 2 Answers

How to call a function from a script in another scene 5 Answers

Is there a way to override a function in each instance of the same script? 3 Answers


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