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 09, 2014 at 08:06 AM by fafase for the following reason:

The question is answered, right answer was accepted

avatar image
2
Question by Mekanofreak · Oct 07, 2014 at 05:12 AM · buttoncoroutine4.6

Is it possible to start a coroutine using a button from the new UI system (4.6)

I tried Starting a simple coroutine using a button created with the new UI system, but everytime I have a yield in my fuction it stop appearing in the button's function selector drop down menu in the inspector, the coroutine is a really simple :

while(true) { do something; yield }

Is there something special i need to do or is it just impossible to start a coroutine with a button using the new UI system ?

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

  • Sort: 
avatar image
9
Best Answer

Answer by fafase · Oct 07, 2014 at 05:14 AM

You cannot directly called the coroutine since your method needs to return void but you can just use a wrapper.

 public void Wrapper(){
     StartCoroutine(MyCoroutine());
 }
 private IEnumerator MyCoroutine(){
     yield return null;
 }
Comment
Add comment · Show 4 · 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 Mekanofreak · Oct 08, 2014 at 10:23 PM 1
Share

Simple workaround, works like a charm, thanks !

avatar image fafase · Oct 09, 2014 at 08:06 AM 0
Share

As a side note you may know but in case, if you wish to prevent multiple calls.

 private bool isRunning = false;
 public void Wrapper(){
     if(isRunning == false){
        StartCoroutine($$anonymous$$yCoroutine());
     }
 }
 private IEnumerator $$anonymous$$yCoroutine(){
     isRunning = true;
     // Do your stuff over multiple frames
     yield return null;
     isRunning = false;
 }

avatar image Chino_96 · Aug 21, 2017 at 02:39 PM 0
Share

I know that this is old but i would be glad if you can tell me how can i attach a this to a button

avatar image Shiner252 Chino_96 · Aug 22, 2017 at 07:13 PM 0
Share

After you've added a UI Button component to an object, you should go into the button's inspector and drag the gameObject into the button component. After the gameObject is referenced, you can select a method from a dropdown menu. $$anonymous$$ake sure your method is public.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Can't change UI Button Listeners 1 Answer

ArgumentException: method return type is incompatible 1 Answer

How to create a button for every supported resolution? 1 Answer

4.6 UI Change what 'Spacebar' is doing by default 1 Answer

Unity 4.6 Button onClick not working in Scenes 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