Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
Alchemist11th's avatar
1 year ago
Solved

Unity OVRInput.Get() caching for performance?

In Unity, I normally cache any GetComponent() if I plan on using it within the Update().  Is the OVRInput.Get similar?  Everyone online seems to just put code like OVRInput.Get(OVRInput.RawButton.X) directly in Update() and even inside their IF statements.  Is this the recommended method for performance?  Is the OVRManager handling everything and I just need to call the OVRInput.Get and not worry about it.  What about if I am using that OVRInput.Get in multiple if statements in my script?  Should I assign the OVRInput.Get as a boolean at the beginning of the Update() and then use that in my script or would that only really help readability but not have an impact on performance?

Thanks!

 

  • At least what I have seen is unlike GetComponent(), OVRInput.Get is already optimized internally. The OVRManager handles input polling and state management efficiently, so you don't need to cache these calls like you would with GetComponent(). When you call OVRInput.Get(OVRInput.RawButton.X), you're essentially just checking a value that's already been updated by OVRManager in its internal update cycle. It's more like checking a property than performing an expensive component lookup. If you're using the same input check multiple times within the same Update() cycle, it would be marginally more efficient to cache it.

2 Replies

Replies have been turned off for this discussion
  • At least what I have seen is unlike GetComponent(), OVRInput.Get is already optimized internally. The OVRManager handles input polling and state management efficiently, so you don't need to cache these calls like you would with GetComponent(). When you call OVRInput.Get(OVRInput.RawButton.X), you're essentially just checking a value that's already been updated by OVRManager in its internal update cycle. It's more like checking a property than performing an expensive component lookup. If you're using the same input check multiple times within the same Update() cycle, it would be marginally more efficient to cache it.