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
1
Question by tuf91497 · Feb 03, 2019 at 06:53 PM · scripting problemvrcollidersoculusoculus rift

[Oculus SDK] How to add colliders to OVRGrabbable at runtime?

I generate objects at runtime that need to be grabbable. In the editor this is easy: drag the collider over the Grab Points field of OVRGrabbable and you're done. But how do I do this in script?

Actually I have this working already but only if my grabbable object has a single collider, not a compound collider. If anyone wants that, just add this code snippet to the OVRGrabbable script:

     virtual public void CustomGrabCollider(Collider collider)
     {
         m_grabPoints = new Collider[1] { collider };
     }

And then you call that wherever you generate your object and send the object's collider as argument. It's worked well for me, but now I need to do it with compound colliders.

In the editor it is again much easier. Even with compound colliders, I just drag my child object with all of the colliders attached over the Grab Points field (once the game is running and the object generated), and grab points becomes volume "1" with what looks like a single collider alt text and it works perfectly, and I can grab the object at any point on its compound collider. Obviously now I need this to happen automatically in script and to not be reliant on me adding it from the editor at runtime. Can't figure it out though. This is the best I have so far (This is added into OVRGrabbable):

     virtual public void CustomGrabColliders(Collider[] colliders)
     {
         m_grabPoints = colliders;
     }

But it doesn't work. m_grabPoints shows a volume of 0 in the editor when I use this method.

So, how does the editor add the colliders to m_grabPoints if you just drag an object with colliders onto the protected field? Does anyone know how to make compound colliders work with OVRGrabbable at runtime?

capture.png (7.0 kB)
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
0
Best Answer

Answer by tuf91497 · Feb 03, 2019 at 09:14 PM

Got it:

Go into the OVRGrabbable script and add this line under the m_grabpoints definition:

     [SerializeField]
     protected Collider[] m_grabPoints = { };
     public Collider[] M_GrabPoints { get { return m_grabPoints; } set { m_grabPoints = value; } }

Then, when you have your compound (or single) collider, just set it like this:

 grab = gameObject.AddComponent<OVRGrabbable>();
 grab.M_GrabPoints = compoundColliderParent.GetComponentsInChildren<BoxCollider>();

Or, you know, however. Just feed it at least one collider.

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 glenneroo · Mar 30, 2021 at 10:08 PM 0
Share

2 things:

1st, there is already an accessor available called grabPoints which can be easily extended:

 /// 
 /// The contact point(s) where the object was grabbed.
 /// 
 public Collider[] grabPoints
 {
     get { return m_grabPoints; }
     set { m_grabPoints = value; }
 }

2nd, I don't know how you even got that to work - when calling AddComponent it calls Awake() which then throws an exception if the array is empty. Populating it after calling AddComponent is too late since Awake() is already called. Maybe the script used to be different in 2019? I'm just wondering how Oculus expected us to use this script in code, or maybe not?

avatar image
0

Answer by glenneroo · Mar 30, 2021 at 10:14 PM

Here is the real solution: https://stackoverflow.com/questions/51503014/how-to-instantiate-an-oculus-grabbable-object-at-runtime-in-unity

In case that link dies, here is a copy/paste:


Read-only properties are properties that can be assigned only through the script that contains them. This means that you can only change the value of grabPoints from inside the OVRGrabbable.cs script.

The best way to do this is by adding a custom function inside the OVRGrabbable.cs file so that you can access and set the read only variables.

I use this one so I can also set the snapPosition and snapOrientation fields as well as the grabPoints.

 public void Initialize(bool snapPosition, bool snapOrientation, Collider[] grabPoints)
 {
     m_snapPosition = snapPosition;
     m_snapOrientation = snapOrientation;
     m_grabPoints = grabPoints;
 }

You'll be good enough only adding and calling the following one:

 public void Initialize(Collider[] grabPoints)
 {
     m_grabPoints = grabPoints;
 }

Also to note, comment out the Awake() function in OVRGrabbable.cs as well and instantiate as follows:

 go.AddComponent<OVRGrabbable>().Init(collider);

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

209 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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 make Oculus Touch door opening 0 Answers

How to disable automatic recentering when using OVRCameraRig 0 Answers

Virtual Reality Toolkit 1 Answer

Pulling Object forwards and back "Oculus VR" 0 Answers

How to stop a video using the OCULUS script MoviePlayerSample.CS. 0 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