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
0
Question by Xathos · Feb 28, 2011 at 04:10 AM · yieldongui

Yield not working within OnGUI()

I've been trying to get a GUI system to work using yield (which is, or at least should be, much easier than the alternatives), except that none of my code seems to be working. Come to think of it, I can see the problem with this approach (nothing would be displayed continuously without a loop or something to make it stay in place). Nevertheless, the odd part is that not a single line of code is working on any method that I call from OnGUI() that contains a yield statement, including debug code.

EG:

def OnGUI (): Debug.Log("This works") if GUILayout.Button("First button"): Debug.Log("Pushed first button") Test()

def Test (): Debug.Log("But neither this") if GUILayout.Button("Nor this"): yield GUILayout.Label("Nor this") Debug.Log("Nor this works")

This has become.... quite frustrating.

I guess it will be back to the drawing board with xml and parsers if I can't get this scripting solution to work. (It's for a conversation system, btw. I thought, why bother with more arrays and data languages if I can get it to work just using scripts? Much simpler; more powerful... now this).

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

2 Replies

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

Answer by PrimeDerektive · Feb 28, 2011 at 02:23 PM

I'm not sure exactly what you're looking for, but I think something like this would work:

private var isTalking : boolean = false;

function OnGUI(){

 if(GUI.Button(Rect(10,10,150,30), "Start Conversation") && !isTalking)
     StartCoroutine(StartTalking());

 if(isTalking)
     GUI.Label(Rect(10,50,500,30), "This conversation will be displayed for 5 seconds when you click the Start Conversation button.");

}

function StartTalking(){ isTalking = true; yield WaitForSeconds(5.0); isTalking = false; }

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 Xathos · Mar 01, 2011 at 07:35 AM 0
Share

Yes, that would work. It's not the system that I was looking for (build a conversation tree just using scripting - ie plain logic using custom function calls and yield to maintain the conversation's position). Unfortunately that system would be impossible to implement via just scripting, which means that I'll just have to go back to my original plan: build complex editor classes to view, edit, and save conversation scripts using a data language, and load the data at runtime. This is probably 10x more complicated than a scripting workaround, but oh well... those scripts are nearly done anyways.

avatar image
0

Answer by Eric5h5 · Feb 28, 2011 at 04:20 AM

You can't use yield in OnGUI any more than you can use it in Update. OnGUI runs every frame and can't be interrupted or delayed.

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 Xathos · Feb 28, 2011 at 04:29 AM 0
Share

Yes, I'm well aware of that. But I'm using yield in a separate method (Test(), in the above example), so why isn't that working?

avatar image Xathos · Feb 28, 2011 at 04:50 AM 0
Share

Ok, I can't get my code to run via boo, but I was able to get a bit of code running in javascript using yield within a loop. Not that that was what I had in $$anonymous$$d, but yes, you actually can use yield in a method called by OnGUI - though it might just be due to a javascript bug... . Back to the drawing board.

avatar image Eric5h5 · Feb 28, 2011 at 05:42 AM 0
Share

@Xathos: You need to use StartCoroutine in Boo if you want to start a coroutine. However, it's not what you want here, because the function would still be called every frame from OnGUI, so you'd end up with zillions of instances of it running.

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

No one has followed this question yet.

Related Questions

yield OnGUI 1 Answer

Function On GUI 2 Answers

yield WaitForSeconds in OnGUI 4 Answers

How to dispaly list of images from server on GUI? 1 Answer

How to add delay before showing GUI Button? 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