How to use accelerometer/gravity sensor data?

I’ve been trying to read gravity sensor data. The first thing that occurred to me was to look in the input settings dialog. There, I found I could bind Tilt, RotationRate, Gravity and Acceleration to my axes. However, an axis returns a float as its value, and these are 3D Vectors, so I don’t really see how binding them can help, not to mention that the defined axis returns zero anyway. Afterwards, I came up on this:

Namely, UPlayerInput::InputMotion which returns all the aforementioned values in the correct FVector format. I can poll this function every tick, but that’s not the “standard” way input handling is done in UE4. So, is there some way to actually bind accelerometer data to an axis, or do I have to poll it every tick?


UPDATE:

After going through the entire code for PlayerInput and InputComponent, I’ve come to several conclusions:

  1. InputMotion (like all other Input*** functions) FORCES the input to the provided values, overriding any default input from the actual hardware devices. Useless for our purpose.
  2. I didn’t find any key or axis bindings that would return vectors. There is a function for binding touch events that returns the touch location as a FVector, but nothing that deals with keys or axes.
  3. Key values are stored as FVectors, with most keys using only the X component as a float or bool value. I assume, however, that this was meant as a generalization of “Key” to any input functionality. This explains why there is a “key” named tilt. Still no way to bind to the FVector value.
  4. Last, there IS a function called “GetVectorKeyValue” in UPlayerInput, which is the closest I’ve come to reading the values I want. Unfortunately, this function returns (0, 0, 0) all the time, so I’m guessing there must be some way to activate gyroscope input (something like Unity’s Input.gyro.enabled), but I haven’t found anything yet.
  5. There were no tilt or gravity related blueprint nodes that I could find.

Ideas, anyone?


UPDATE: Now I’ve seen it all. I just read through a bunch of the android-related source files (did you know UE4 supports android gamepads by default, including the DualShock3?), still found no mention of gyroscope data, and all related functions are still returning zero…

If you plan to apply motion change in every on frame then there no other way to do that then Tick(), so go ahead. Alternatively you could use Axis input events and send that from all methods to single method which will set the result.

Yea but you seems to be concerned to use Tick(), i explain you alternative method which will call when it’s changed.

Make a function called for example UpdateMotion and send new data as argument and update you variables ot that motion thru with this method you will end up set up 3 times for each axis :stuck_out_tongue:

In you case i would just use Tick(), engine default physics systems updates objects every frame so Tick() (or ComponentTick()) is used all the time in it.

Well, the question is, how do I use axis input events? Also, axis input events are called every tick unless idle, so it produces the same result I think.

Well, I’ve just been all over InputMotion, it’s giving me crap (literally). The values it reports are 30 digits or so long. It looks a lot like uninitialized C variables to me. Is there some kind of “On/Off” switch for g-sensor data or something?

Hi . Thank you for your feedback regarding using the accelerometer for input. We are aware that the motion controls are not currently returning usable values, and plan on rectifying the situation soon.

Have a great day.

Hi ,

Have you been able to get this working for you? I will be marking this issue as resolved for tracking purposes, but please feel free to reopen it if you are still not seeing the results that you would like.

Why is this question marked complete when nobody has provided an answer as to the issue? Has this been corrected in subsequent builds?

Hi BenFreidlin,

Access to accelerometer data has been activated in the Engine, and we are still doing some work to improve on it. This post was marked as resolved for our internal tracking purposes since it had been some time since anyone had provided either additional information about the issue or a potential work around.

When you say ‘activated in the Engine’ can you expand upon this? I understand that you are currently trying to improve upon it, but any sort of workaround or pointing in the direction of a solution, or an update on where the engine is at with this would be appreciated.

Hi Osok,

The Engine is now able to receive and use data from the accelerometer. If you are having trouble getting it working, I would recommend posting a new question with details about what you are trying to accomplish.