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 mage76 · May 10, 2017 at 02:08 PM · inputvrvirtualcontrollers

user input

My code involves me waiting for user input. The code cannot progress unless the trigger is clicked on the vive controller. However, when I try to incorporate a while loop, unity crashes.

    void ThrowBall()
    {
      trackedController = GameObject.FindWithTag("Right Controller").GetComponent<SteamVR_TrackedController>();
     
     ballscript = GameObject.FindObjectOfType(typeof(BallScript)) as BallScript;
     if (ballscript.getLocation() == 2)
     {
         self.StopPlayback();
         player1.StopPlayback();
         player2.StopPlayback();
         self.Play("idling");
         player1.Play("idling");
         player2.Play("idling");

         while (trigger == false)
         {
             int x = 0;
             x = x + 1;
             Debug.Log(x);
         }

     }

     ballscript.ReleaseMe();
 }
Comment
Add comment · Show 3
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 mage76 · May 10, 2017 at 04:11 PM 0
Share

would i be able to check for a trigger input in update? would that work?

Or actually let me just explain the whole thing to you. I have a little ball throwing script with 2 automated people and a real person. I want the people to idle while the real person doesnt hit the trigger yet. When the trigger is hit, I want the animations to continue

avatar image NoseKills mage76 · May 10, 2017 at 09:16 PM 0
Share

Unfortunately i can't remember how the input works in Vive... it's been a few months. But I'm sure some method gets called or some boolean gets set to true when a trigger is pressed.

The animation system of Unity makes it pretty easy to make a "state machine". You don't have to do anything special, like go into a loop, if you want to wait for stuff to happen.. Just set your animations to idle when the game starts (if i understand correctly) and set up the animation controller so that the animations stay idle until, where ever you react to player input, you tell the animator to go into the next animation. Then stay there until something else happens that requires an animation change.

You are now telling the animator to play the "idling" animation. If the animation changes to something else without you asking it to, it's a problem in the animator's transition conditions.

avatar image Bunny83 · May 10, 2017 at 09:26 PM 0
Share

Btw: Unity did not crash but hang / got stuck in your loop. Just wanted to put the ter$$anonymous$$ology right -.-

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by NoseKills · May 10, 2017 at 03:16 PM

Unity apps are single threaded programs unless you make new threads yourself. Each thread executes the code line by line by line (simplification). Since you got only one thread, the execution of code can only be happening at a singular point at any given time. So when you have a loop like this

 while (trigger == false)
 {
      int x = 0;
      x = x + 1;
     Debug.Log(x);
 }

those are the only 3 lines of code that are executing in the whole app. That's including the code in Unity's engine where animations are played, screen is redrawn, sounds are played, and most importantly in your case, input is gathered. Unity can't even display the Debug.Logs since it's stuck in the loop (since you reintroduce int i every time in the loop, it would print out 1 every time anyways)

Nowhere inside that loop you give trigger a chance to change its value so the loop could ever end.

You don't say what it is you actually want to do in that loop/instead of the loop, but whatever it is, you have to enable changing trigger back to true inside the loop. Or setting a proper start condition, doing your stuff in Update while that lasts, and making another condition for stopping doing it.

If what you want to do requires the screen to be redrawn after each change (animating a position or such), you'll have to do it the latter way (no loop, just do stuff each Update as a condition is met) because a tight loop won't allow it.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

how to make gaze input on vr cardboard has 3 seconds to respond command 0 Answers

VR Navigation ala TiltBrush or Quill 1 Answer

SteamVR 1.2.0 - only first two connected controllers give button input 0 Answers

Getting started with VR (Vive) and unity 5.5.0 0 Answers

How do I determine the rotation of the XR unity controller if it is held upright or held facing down 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