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 NoahDaNerd · Oct 11, 2020 at 05:38 PM · vroculus riftstackoverflow

Stack Overflow Error and I cant find any recursive methods

I am trying to create a system for object interaction in VR, but whenever I release the grip, the release function causes a stack overflow.

This is called on the hand whenever the value of the grip is changed (does not seem to be the issue):

 private void Grip(float val)
     {
         anim.SetFloat("Grip", val);
         if (val > gripButtonThreshold && !isGrabbing)//If holding down grip (only at start)
         {
             //find closest object
             GameObject closestInteractable = FindObjectOfType<Interactable>().gameObject;
             foreach (Interactable obj in FindObjectsOfType<Interactable>())
             {
                 if (Vector3.Distance(holdPoint.position, obj.transform.position) < Vector3.Distance(holdPoint.position, closestInteractable.transform.position))
                 {
                     closestInteractable = obj.gameObject;
                 }
             }
             closestObject = closestInteractable;
             isGrabbing = true;
         }
         if (val < gripButtonThreshold)//If not holding down grip
         {
             if (isGrabbing)
             {
                 isGrabbing = false;
             }
             if (hasObject)
             {
                 holding.GetComponent<Interactable>().Release(this);//Call release on interactable script
             }
         }
     }

This is the code on the interactable script (this seems to be the issue):

 private void OnTriggerStay(Collider other)
     {
         if (other.TryGetComponent(out Hand hand) && hand.isGrabbing && hand.closestObject == gameObject && !hand.hasObject)//if a hand is grabbing and colliding with you (only called once)
         {
             //Call method set in inspector (Pick Up in Movable Object)
             for (int i = 0; i < OnInteract.GetPersistentEventCount(); i++)
             {
 ((MonoBehaviour)OnInteract.GetPersistentTarget(i)).SendMessage(OnInteract.GetPersistentMethodName(i), hand);
             }
         }
     }
 
     public void Release(Hand hand)//called by hand once, but causes stack overflow
     {
         //call method set in inspector (release in MovableObject)
         for (int i = 0; i < OnRelease.GetPersistentEventCount(); i++)
         {
             ((MonoBehaviour)OnRelease.GetPersistentTarget(i)).SendMessage(OnRelease.GetPersistentMethodName(i), hand);
         }
     }

Finally, Here is the code on movable object (this might be the issue):

 public void Release(Hand script)//called from interactable through inspector
     {
         rb.isKinematic = false;//make the rigidbody do stuff now
         rb.velocity = velocity;//set the velocity to the velocity while kinematic
         beingHeld = false;
         transform.parent = null;//unparent from hand
         script.holding = null;//set handto be not holding
         script.hasObject = false;//set hand to be not holding
     }
 
     public void PickUp(Hand hand)//called from interactable through inspector
     {
         hand.hasObject = true;//set hand to be holding
         rb.isKinematic = true;//set rigidbody to be still
         hand.holding = gameObject;//set hand to hold self
         beingHeld = true;
         holdPoint = hand.holdPoint;
 
     }
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
0
Best Answer

Answer by NoahDaNerd · Oct 14, 2020 at 09:18 PM

It was because I had the methods in the movable object and interactable set the same. I do not know why that caused a problem, but it did.

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

178 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 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 can I let a VR player walk up walls using Oculus' OVR Camera rig? 0 Answers

Unity Build not running on Oculus DK2 3 Answers

RenderTexture in VR/3D 0 Answers

How to fix Camera "corner cut" artefact 0 Answers

projet convert video 2D to virtual reality 3D in Unity with Oculus Rift 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