x


Reading input outside of Update or some other ticking system

Hey, I'm working on removing as much as possible from Update(), or anything else that ticks like a mo-fo. I wondered if it was possible to read keyboard input that isn't dependent on checking EVERY FRAME if(Input.GetKeyDown) or what ever.

I'm still a n00b, but it seems like that's SUCH a sloppy way to do it. is there some sort of keypress event that I can listen for instead? if not in unity, perhaps in .Net?

I have decided that ticking is for suckers.

more ▼

asked Feb 20, 2011 at 07:20 AM

hypnoslave gravatar image

hypnoslave
453 42 34 44

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Ticking might seem like it's for suckers at first, but you have to remember that every frame of your game the computer is pumping that scene data to your GPU, then getting it to transform every polygon and paint it on the screen. There's millions of cycles being used to do the same thing over and over 60 times a second.

An if statement in an update function is nothing compared to everything else that's going on.

The alternative is what Eric5h5 said: callbacks on keypress. And like Eric said, callbacks aren't available in Unity. You could wrap the input class in something that emulates callbacks, but you'd still need to put it in a ticker function somewhere.

The input loop is still being used even after decades of game development because it's fast and simple.

more ▼

answered Apr 04, 2011 at 06:39 PM

Parthon gravatar image

Parthon
240 8 9 20

Interesting, guys, Thank you both! I'll give you both a check-mark if i could. Ting!

Apr 04, 2011 at 06:49 PM hypnoslave
(comments are locked)
10|3000 characters needed characters left

There aren't any input callbacks unfortunately. You have to check every frame (or at least every frame that you're expecting that input can occur).

more ▼

answered Feb 20, 2011 at 09:00 AM

Eric5h5 gravatar image

Eric5h5
114k 59 216 715

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1651
x848
x811
x304
x17

asked: Feb 20, 2011 at 07:20 AM

Seen: 1803 times

Last Updated: Feb 20, 2011 at 07:20 AM