Discussions

Ask a Question
Back to All

Decoupled input of all joystick interactions

Hey,

First off, thanks a million for creating this awesome system, and especially giving it away for free!!!

I love how you are grouping the SteamVR plugin, and OVR into one, cohesive SDK.

My question is how do you go about getting all the joystick interactions through NewtonVR? Basically, I would like to decouple the Input from my custom scripts using UnityEvents. However, I keep getting an error when I try to access the button Inputs dictionary. It doesn't seem to be returning anything. Here is my script.....

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

namespace NewtonVR
{
public class NVRHandInputCallbacks : MonoBehaviour
{
public NVRHand hand;
public NVRButtons button;

	public UnityEvent OnButtonPress;
	public UnityEvent OnButtonRelease;

	public NVRButtonInputs buttonInputs;  // only public for debuggin

	// Update is called once per frame
	void Update()
	{
		if (!hand.Player.isActiveAndEnabled) return;

		buttonInputs = hand.Inputs[button];

		if (buttonInputs.PressDown)
		{
			OnButtonPress.Invoke();
		}

		if (buttonInputs.PressUp)
		{
			OnButtonRelease.Invoke();
		}
	}
}

}

However, when it runs I get this error:

NullReferenceException: Object reference not set to an instance of an object

NewtonVR.NVRButtonInputs.get_PressDown () (at Assets/Plugins/NewtonVR/NVRButtonInput.cs:17)

NewtonVR.NVRHandInputCallbacks.Update () (at Assets/07_Scripts/Input/NVRHandInputCallbacks.cs:26)

Should I not be trying to access that dictionary? Is there another way to get the Input data for all of the controller input?

thanks a gazillion!!!
-Trentity