Recording Input State....

I was wondering if anyone has an easy way to record the state of the input device. I come from an XNA background and they have a handy KeyboardState object that holds all the current tick’s information about the keyboard. I was wondering if unity had something along those lines or if it only gives me access to the input information through the Input class. Thanks for any help.

That’s basically what the Input class does (among other things). GetKey()/GetButton() will tell you whether a key/button is currently down, and GetKeyDown()/GetButtonDown() will tell you whether the key/button was pressed on this update.

Is that what you’re looking for?

That is for getting the current tick’s input data, but there is there a way to easily store that data for later use?
something along the lines of

public class myClass:Monobehavior
{
  list<Input> inputHolder;

  void update()
  {

     inputHolder.Add(Input);
  }

}

then when you fed input to an object you would just say something like

int i = 0;
update()
{
currentinput = inputHolder[i];

if(currentInput.ButtonIsDown("MyControl"))
{
//do stuff
}

prevInput = currentInput;
i++;
}

Basically what I want to achieve is a time clone type thing where the player can “reset” and they will have a ghost that did everything they just did.

I think you’ll probably have to code that manually. But, I wouldn’t think you’d want to save the entire input state every tick for something like this anyway (since presumably there’ll only be a few input events that’ll actually be of interest).

Also, be aware that getting an exact replay can be tricky in some cases due to factors such as varying update rates and so forth. (Not saying this is a problem you’ll run into necessarily - it’s just something to be aware of.)

Yeah if I have to code it manually I would only do it for the keys that are actually controlling the game. No point in storing useless data. Just wanted to know if there was a simpler way to do it that I didn’t know about. Thanks for your help it is greatly appreciated.