[30USD] SteamVR UI Input System


SteamVR - UI Input Module v1.0

Link to the store: SteamVR - UI Input Module
Easy integration of the SteamVR controllers with Unity’s uGUI system.

It also can be used as a base to extend unity’s input system (Input and GraphicRaycaster modules)

It includes a custom Input Module and a custom Graphic Raycaster allowing to use steam vr controllers to interact with the Unity native UI system.

Instructions:

  • In the EventSystem gameobject remove (or deactivate) Unity’s Input Module (usually Standalone Input Module)
  • Add our SteamVR Input Module
  • Add at least one Steam VR Pointer and configure which physical controller should follow
  • (Optional) Add a line renderer prefab to use it as a laser beam
  • (Optional) Add a object to use as a hit indicator
  • In your canvas (or canvases) remove (or deactivate) Unity’s Graphic Raycaster
  • Add our SteamVR Graphic Raycaster

All native controls work, including Scroll View and the controller virtual Scroll wheel

Full source code is included, as well as an example scene showing every native control. I use this asset for my own projects, so I will keep improving and expanding it.

If you have any comments, doubts, feature request or find some control misbehaving just let me know

Finally the package is accepted and live in the store!

How can I change the angle/position at which the ray comes out? I’d like to make it so that it comes out of where the hand would be (like a pointing motion) instead of the top (like a thumbs up).

For the drawing of the ray you should modify SteamVRPointer, the region named “Laser and Hit”, and you will also need to adjust the RaycastAll method in the same class, most likely change the “worldNormal = m_trackedObjectTransform.forward” to your needs

Created a new variable PointerObject which is just a gameObject nested inside the controller that it uses to define m_TrackedObjectTransform. Works like a charm!

Thanks for pointing me in the right direction, your UI system is fantastic :smile:

That’s a very good and elegant solution!

I’m glad you like it :stuck_out_tongue:

Hey I bought your asset! A few questions:

  • How do I also support mouse and keyboard?

  • I wanted to recommend a better folder structure similar to most of Unity’s packages (seperate scripts, materials, prefabs, scenes etc). Can explain more if you don’t know what the structure is.

  • Is it possible to use this for Gaze only (instead of SteamVR controller)?

  • Is there a repo I can be added to so I can contribute?

Thanks!

Hi Taiku, thanks for buying it. Your answers:

1.- Not by itself, you will have to add the proper input module and activate one or the other.
2.- I know that structure, but I dont like it, I can see in the project view what is a script, what is a material etc… I dont need to have them in different folders to organize them. Instead I prefer to separate in folder by concept, and avoid ending up with a huge script folder containing scripts that doesnt have to do anything with each other.
3.- Again, it is possible, but you will have to create a new input module (you can take the one included as a starting point)
4.- Sorry, I can’t give you access to my private repo. But if you think something is worth to contribute you can post it here and I can add it to the asset if it’s useful to the community (also I dont want to take credit from your work)

  • More about the folder structure. If you are developing a war game (lets say a better version of CoD inifinite crap) a tutorial will suggest something like this for the guns:
+ ...
   + Guns
         + Scripts
          |      + Knife.cs
          |      + Gun.cs
          |      + Rocket.cs
         + Materials
          |      + Knife.mat
          |      + Gun.mat
          |      + Rocket.mat
         + Prefabs
                 + Knife.prefab
                 + Gun.prefab
                 + Rocket.prefab

Now as the project grows, each time you want to add a new weapon you need to add new files in 3 different folders (probably more). I prefer to have separate folders per concept, so each new concept will be self contained in its folder:

+ ...
   + Guns
         + Kinfe
          |      + Knife.cs
          |      + Knife.mat
          |      + Knife.prefab
         + Gun
          |      + Gun.cs
          |      + Gun.mat
          |      + Gun.prefab
         + Rocket
                 + Rocket.cs
                 + Rocket.mat
                 + Rocket.prefab

This structure also makes more sense if you want to use asset bundles (which you probably want)

Hmm I thought it added SteamVR input - not replaced mouse and keyboard. For my needs its not as useful without that.

I can see why you might like that way but it comes down to preferring composition over inheritance. Everything should be as independent and generic as possible. Prefabs are the composition that bring them together. You shouldn’t really able to separate cleanly into a hierarchy.

For example:

+ Models
        Hilt
        Barrel
        Scope
+ Scripts
         ProjectileSpawner
         Reloadable
         DamageDealing
+ Prefabs
         Rocket (DamageDealing) {Hilt, Barrel}
         Gun (Reloadable, ProjectileSpawner-> Rocket) {Scope, Barrell}
         Knife (DamageDealing) {Hilt}

If it was a reusable asset (or for one) I would still follow this structure but would simply start at a higher level so I could export, maybe Weapons → Materials, Prefabs, Etc.

Even if I was to follow your example inside each of those folders I would still split by type - into Script/Material/Prefab because it could get easily cluttered and in general I’m looking for something for gun - example I want guns prefab not a list of all dependencies of gun. And as you add more scripts or different materials or sounds the list grows and grows.

Even granted the composition above, I wouldn’t want one super massive Materials/Models folder, so I would still split at the highest level possible.

For this asset it was hard to identify where the prefabs were at first, I thought they weren’t included - folders by type would have helped - or even the organization you showed above.

Everything is just dumped into a UI folder. I fail to see any organization.

2849524--208175--ddd.PNG

SteamVR input replaces standalone input because it doesn’t make sense to have both active at the same time (moving the camera with the HMD and the mouse at the same time can be very dizzy) but it uses composition, you can have both at the same time and activate one or another.

About the folder structure, I didn’t say that one structure is better than another I just explain why I prefer that and which one in my experience works better.

You can add more folder depth to separate scripts, prefabs etc… but when there aren’t many files (like in this case) I prefer something cleaner and just be able to see everything at the same time.

In unity, and software development in general, there isn’t just one right and one wrong is just about decision and being able to take and explain that decisions.

It all comes down to: does the asset work for you? do you need some help to integrate it into your idea? Moving files around if you prefer some other organisation shouldn’t be a problem

I agree that there is not a right way, I was explaining why most prefer the other - and it just seemed like this asset didn’t have any structure at all, so I just wanted to recommend a structure most of the asset community uses, the unity tutorials teach and is generally accepted as best practices. But I understand why you want to keep your own for your own preferences.

It can make sense if you have a PC camera and a SteamVR camera and would like a shared UI they can both access. Kind of like fantastic contraption has a menu on the PC - but I also want the SteamVR player to be able to access it. It might be a niche use - but its what I was looking at.

@arklay_corp Great asset! Thank you for this. I am having a couple small issues that I would appreciate some help with though. For some reason, whenever pressing a button on a canvas there is some weird flickering of the UI happening. This doesn’t show up in the editor game view, only in the headset. All the buttons and other UI elements work the UI just flickers whenever a button control is clicked on. Also I can’t seem to get the hit indicator to show up and the line renderer renders through the canvas. Again, the UI elements work fine, but I feel like the intended behavior isn’t happening. Thanks again for the module, please help if you can.

Hi @Mister_Horrible_1 , thanks for your compliments, they mean a lot :slight_smile:

Can you share which unity version are you using? as you can see the code doesn’t have anything to do with the rendering so the flicking you are seeing must be related with something else… are you using custom shaders? or maybe your UI components share the same z coordinate?

@arklay_corp I’m using 5.4.3f1

I am using the Lab Renderer in this project, so I’m beginning to wonder if that has something to do with the flickering. Any idea why the hit indicator never shows up and the “laser” pointer goes through the canvas? The buttons and all other UI objects work, but I just thought that I would be seeing the sphere object show up where the laser hits the canvas. I have populated the Steam VR Pointer script attached to my Event System with the hit prefab, but never see it.

It’s very weird, it’s just a simple raycast, if the system works properly (the right UI element gets hit) the sphere should appear in that element.
Where does the sphere actually appear? too far, too close, it doesnt shot at all?

The sphere doesn’t show up at all and the the line renders through the canvas, but the buttons still work.

Could you send me somehow your project (or an example) for me to reproduce the problem and help you out?

The issue turned out to be a scaling problem. My SteamVR play area was scaled up very large for the specific project I was working in. Once I scaled down the camera rig/play area to (1,1,1) and resized the canvas everything worked perfectly. Thank you for all your help and the wonderful module!

Great, GeoJohn! I’m glad you solved it.

And thanks for your compliments

Hey. I just bought the Asset. Works great :smile:
I got a question though:
The way it works right now, when dragging a slider, but loosing focus of the handle with the pointer, the drag stops & the slider gets deselected.
Can I change it somewhere, so that while the trigger is pressed & dragging it doesn’t loose focus?