Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 asif_farooq · Sep 03, 2019 at 02:38 PM · variableupdatetest

Variable value not updating in test script

Hi, While running some tests I am stuck at something I do not understand. There is a Boolean variable in my test script whose value I get from a script attached to a game object inside the scene that I am loading at the start of the test. The code is below :

          PrepareScene();
         yield return null;
        //yield return new WaitForSeconds(10f);
         Testbool = GameObject.Find("TestSuite").GetComponent<TestSuite>().hasLoaded;
         while (Testbool == false)
         {
             yield return null;
         }
   

In the above piece of code I am assigning the value to the Test bool. However the value of test bool remains to be false forever and the test gives me a timeout error after 30 secs even though I am sure that hasLoaded becomes true at some point. If I use waitforseconds(10) and then assign the value of Testbool it becomes true. But the value of Testbool does not update once it has been assigned

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
1
Best Answer

Answer by karl_jones · Sep 03, 2019 at 02:45 PM

You are getting the TestBool, by value, not reference. https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/value-types

 Testbool = GameObject.Find("TestSuite").GetComponent<TestSuite>().hasLoaded;

This is copying the value into Testbool. If the value of hasLoaded changes it will not be reflected back to TestBool. You should instead hold a reference to the GameObject and check hasLoaded directly.

  var suite = GameObject.Find("TestSuite").GetComponent<TestSuite>();
  while (suite.hasLoaded == false)
  {
      yield return null;
  }

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 asif_farooq · Sep 03, 2019 at 02:59 PM 0
Share

Hi, thank you I have solved this issue. I have one more question though, my test script is derived from TestSuite and TestSuite has a bool named hasloaded.

I cannot just use this in my test script?

while(hasloaded == false) { yield return null; }

avatar image karl_jones ♦♦ asif_farooq · Sep 03, 2019 at 03:32 PM 0
Share

Yes you can do that

avatar image asif_farooq karl_jones ♦♦ · Sep 04, 2019 at 04:24 AM 0
Share

That does not work though

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

120 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 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 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 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

How to change the rate of decrease in a variable in the update function 1 Answer

Access a variable from another script in update function 1 Answer

Why a public varibale is not accsible inside Update() ? 1 Answer

coroutines : trouble editing and accessing the same public variable 4 Answers

Variable updates everywhere but Update function. 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