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 Grimmy · Dec 21, 2010 at 02:02 PM · functionyieldargument

Can a function maintain its argumanet data after it is run?

Thats a question thats crossed my mind when trying to figure out this problem..

I'm trying to figure out a very wierd bug. I run the following code and the first time the function is run everything is okay (a person gets loaded), but the second time it gets called it doesnt work.

randomMysteryGeneratorScript.personScript[0]=randomMysteryGeneratorScript.personObject[0].GetComponent(Person); yield Load_Person(randomMysteryGeneratorScript.personScript[0]);

 //FOR SOME REASON THIS next one DOESNT LOAD THE 2ND PERSON...even though its the sme function!!!!!!!!!!!!!!!!!!!!!!!!!!!!!???????????????????????????
 randomMysteryGeneratorScript.personScript[1]=randomMysteryGeneratorScript.personObject[1].GetComponent(Person);
 yield Load_Person(randomMysteryGeneratorScript.personScript[1]);

What can be possibly different about the second run? There is no error as such, instead the person does not get populated with any data. (but this is fine on the first run??)

Comment
Add comment · Show 4
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 Mickydtron · Dec 21, 2010 at 02:20 PM 0
Share

what happens if you comment out the first yield Load_Person(...); line? does the second one execute properly in that case?

avatar image Grimmy · Dec 21, 2010 at 02:33 PM 0
Share

Good question, I just tried removing the first one but the second one still doesnt excecute.

avatar image burnumd · Dec 21, 2010 at 03:48 PM 0
Share

Can you give some more context? Any time you use a yield, it's helpful to know what the function you're yielding does, as it's likely that's where the problem is.

avatar image burnumd · Dec 21, 2010 at 03:50 PM 1
Share

Also, to answer the title of your question, a function never "remembers" arguments. See this Wikipedia article for a primer on scope: http://en.wikipedia.org/wiki/Scope_(program$$anonymous$$g)

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Grimmy · Dec 21, 2010 at 02:38 PM

I just tried the following and it still doesnt work DESPITE the fact that both print commands DO display the correct names.

currentPersonScript=randomMysteryGeneratorScript.personObject[0].GetComponent(Person); print("ScriptName0:"+currentPersonScript.name); yield Load_Person(currentPersonScript);

 //FOR SOME REASON THIS DOESNT LOAD THE 2ND PERSON.
 currentPersonScript=randomMysteryGeneratorScript.personObject[1].GetComponent(Person);
 print("ScriptName1:"+currentPersonScript.name);
 yield Load_Person(currentPersonScript);

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 Statement · Dec 21, 2010 at 04:08 PM 1
Share

It leads me to think you have a bug in function Load_Person.

avatar image
0

Answer by Mickydtron · Dec 21, 2010 at 05:08 PM

Well, if the second call does not work even when we do not execute the first call (thus making the "second" call the first one to actually go), then the first call is obviously not messing things up for the second one, and there is a problem with the line

yield Load_Person(randomMysteryGeneratorScript.personScript[1]);

Also, as stated above by burnumd (upvoted), the principles of scope dictate that the variables of one call will not bleed over into the next call. Unless they are static variables, which are shared across all instances of something. I was curious if the yield was not working properly, and would suggest fully expanding the yield statement. That is:

yield StartCoroutine(Load_Person(...));
Comment
Add comment · 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

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

StartCoroutine important for using yield? 1 Answer

How to use yield within a class function 2 Answers

Use yield WaitForSeconds to delay mouseover on a gameObject? (JS) 1 Answer

How can I use a yeild during an udate? 1 Answer

Yield Causing function not to be called on multitouch script 2 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