Object reference not set to an instance of an object... this is getting on my nerves

hey ive had this error for a while and would realy like to get it fixed. im tired off looking at it when im in unity. my game still works fine i guess this just slows it down.

Error:

NullReferenceException: Object reference not set to an instance of an object
OVRPlayerController.UpdateMovement () (at Assets/OVR/Scripts/OVRPlayerController.cs:240)
OVRPlayerController.Update () (at Assets/OVR/Scripts/OVRPlayerController.cs:158)

Line of code:

line 240: if (hydraController.JoystickY >= 0.1) moveForward = true;

and heres the input thingo for hydraController( you need this line in the same function as your getting the inputs) NOTE these 2 line are in the same function which is —> public virtual void UpdateMovement()

line 210: SixenseInput.Controller hydraController = SixenseInput.GetController(SixenseHands.RIGHT);

any one who can help me get rid of this error will be my hero and i wont go insane

thanks .Scott

Do you have a hydraController, or a type o in the variable ? In a start function or where ever the hydraController gets assigned use a debug or print to make sure the var is not null.

Yea, generally this exception is generating when you’re attempting to access an instance of an object that has not been initialized or doesn’t existence. You’re literally getting null when attempt to reference it. You need to make sure you’re initializing the object you’re trying to access. If you’re just declaring a field at the top like this:

private HyrdaController hydraController;

Then you will get an exception because it’s not being constructed and it’s expecting to be referenced to something before being accessed.

If that’s the case in either the start, or Awake function or up in the classes’ members you need to set the object to a new instance of itself. At the very least do so with the default constructor. Depending on what it does or is used for you may want to use an overloaded constructor but I cannot know that due to the code. Look below for an example

private HydraController hydraController;

void Awake()
{
     hydraController = new HydraController();
}

not quite sure what you are talking about ill upload a script. NOT the same script that im referencing the lines above in but one thats a bit easyer to understand

EDIT: sorry i dont know how to put those code boxes in

Well, in that case it appears you’re assigning a reference to something to hydraController but it’s possible that

SixenseInput.GetController(SixenseHands.RIGHT);

Itself might be null. You may want to test this. Run this code and check the output

     if(SixenseInput.GetController(SixenseHands.RIGHT) == null)
     {
          Debug.log("It's null");
     }

That might be the issue.

I ran That Code and it does say Its…Null in console

Alright, then at this point you need to focus on determining why SixenseInput.GetController(SixenseHands.RIGHT) is null.

I don’t know what the SixenseInput class is. Have you defined it yourself. If so I’m assuming you wrote GetController method to be static?

no i didnt do the class my self. sixenseinput is a Controller Called RazyerHydra and it use a plugin which comes with a dev kit. i also dont know if GetController Method is static. i know i didnt make it static

You’re going to have to refer to the documentation to see if you’re accessing and using the GetController method properly, their documentation, and if you can’t resolve it they might be the only knows who would know how unless you have access to their code too.

well no documentation came with the dev kit and there is very little info out there on the web about coding for the razerhydra. i do however have access to all the code that makes it work apart from the plugin

This is a shot in the dark since I don’t know the dev kit.

Try running this code

SixenseInput sixenseInput = new SixenseInput();


 if(sixenseInput.GetController(SixenseHands.RIGHT) == null)

     {

          Debug.log("It's null");

     }

This will test to see if you’re suppose to access an instance of the object and not the class’ static methods instead. However, it wouldn’t make sense for there to be static methods you cannot access.

Again this is a shot in the dark. Report back the result but I’m not sure I’d be able to suggest anything more depending on the results.

nah there was still the same error this is one of the main scripts i got with the dev kit

and it doesnt get any errors

Yea I don’t see the GetController method defined there so I can’t really comment. Contact the devs and direct them to this thread. They’ll be able to help.