Pinch event - how does it work? Why is there no documentation?


I’m new to UE4 and I’m finding the lack of Android documentation frustrating. Happy if someone has some good resources to share.

Anyway, I’m trying to implement a simple pinch to zoom. I noticed there is a pinch event which has “pressed” and “released”. I tried it and what seems to happen is that when I press a second finger to the screen it triggers the “pressed” action and when I release the second finger it triggers the “release” action.

It’s triggered even if I try very carefully to just press straight down and not move fingers in a pinch motion. It’s triggered exactly once, ie if I keep 2 fingers on the screen and move them in a pinch motion, nothing further is triggered.

I don’t really see how this helps me or what use this pinch event is. Maybe I’m just not thinking straight. Can someone please enlighten me with what I’m missing?

Any help is greatly appreciated!

I’m having some similar issues. I did manage to setup a Pinch Input in the Project Settings / Engine / Input and using the custom name I assigned - could call it in the BP and specifically call it’s Axis. When running on device I printed out it’s values and pinching gave me a value from 0-14 (14 was the max if I pinch slid as wide as possible, to the opposite corners of the screen). Weirdly though -I can feed this in to the spring arm of a camera to set the distance but nothing happens. I double checked the logic by using the mouse wheel values to do the same and that seemed to work fine. Not sure what’s going on but hopefully this might help you give you some ideas. I think the pinch released/pressed event is just to start the logic gate before you do the further checks using the axis data (though as you said there doesn’t seem to be any docs). There are some custom scripts kicking around for gesture controls but it does seem like pretty basic functionality that should be possible with the vanilla engine.

Thank you, I’ll have another look at the settings next time I get a chance to work at this. Didn’t see what you are describing. Can I ask how you are debugging this? Is it possible to bind the pinch in/out to some keys so I can easily debug it on my computer?

I assume I can debug it on tablet (haven’t tried), but I’m having some additional issues where it takes hours to deploy a level for testing so I usually just do it at night and grab tablet on the morning to test it while on train.

So this is my logic and I’ve included how I can print / debug straight from the pinch

You can drive the same logic using the mouse wheel but I don’t think it’s possible to actually debug pinching itself without doing it on device

I have pinch/zoom almost working now, the logic above will allow to zoom out constantly, just need to add some extra logic

Have it fully working now using similar logic to this


Thanks a lot, I’m looking forward to giving this another go with the help of your examples! :slight_smile:

I was having an issue getting it working myself. I ended up checking for a flick motion on InputTouch. Check it out, there’s no reason one couldn’t do the same thing for pinches:

This takes the start location of any given touch and when the finger is released we check its end location against where it started and if its more than the desired threshold I call an Event. In this case, the user has to swipe UP at least 250 pixels to fire a missile from his ship. The only downside I could see would be if you pressed in the middle, went down and over and then back up it would still read as a flick, and if you went down 100 and then up 300 it would still fail, but if one were so inclined you could update the starting location on Moved. Squeeze isn’t worth the juice in my case.

Just thought I’d give an update.

As there didn’t seem to be an easy way of doing this, I figured I’d just bite the bullet and try my hand at writing the logic myself. It wasn’t too bad really. It’s always hard to look at other peoples code (including blueprints), so in the end I didn’t really try and mimic the code posted in this thread (although I’m sure some of the logic is the same).

The first problem I encountered however was that the inputtouch “pressed” did not register. “Released” was fine. I did a very simple test which was just connected to “print string” so I definitely didn’t make a faulty test case. In hindsight maybe this is because I think I selected to use the mouse for touch in the settings earlier. Although I haven’t confirmed that.

Anyway, for anyone interested, by logic was basically as follow:

  • on pinch event I simply set a variable to say that I was (or was not) pinching. Using the standard touch input when pressing finger 2 would probably work too (but as mentioned I had problems with that).
  • all the rest was driven from inputtouch move event. I basically just grabbed position of finger 1 and 2 and assigned to variables. Before grabbing this position, I assigned previous position to of finger 1 and 2 to different variables.
  • if all conditions are met (ie all variables where assigned and I was pinching etc) I calculated the x distance between finger 1 and finger 2. I then compared to distance between previous finger 1 and 2.
  • pending on whether difference of these two sums were positive or negative, I moved camera in or out using this value multiplied by a static variable (zoom speed). But only if it was over a certain threshold, to make it smoother. In other words, if I pinched very very slow, nothing would happen.
  • when pinching stopped, I also reset the finger position variables.

I think that’s basically it. Not very difficult logically, but the blueprints did end up surprisingly messy and it felt a bit hacky. But it worked very well, I couldn’t find any issue or annoyance whatsoever when testing. It worked exactly as I’d hoped.

Where should I put this logic though? It’s currently on the level, which isn’t right.

Hi fruxo! would you like to post a screenshot of your blueprint set?
i’m struggling with the same problem
thank u

1 Like