Pencil please

Is there any way to access pressure and tilt of a touch on iOS via blueprint? Are there even any plug ins for this? You would think this would be useful for archvis folks. I can’t even figure out how to get my project to register a touch if the user is using an Apple Pencil. Any help would be much appreciated.

Is it safe to say that the answer is - No, there is no way to access pressure and tilt?

I think in theory you could write a swift framework with the functionality you need and integrate it into ue4, but this is not an easy thing the first time around.

Sorry this is so late but I only just saw this while searching to see if pencil support had been included. I wrote this which worked in UE4.18-UE4.25 and almost certainly works beyond that. Requires building engine from source but add this to the very bottom (past @end) of iOSView.h

struct sDodgyPencilGlobals
{
int Index;
float Force;
float MaxForce;
float AltitudeAngle;
float AzimulthAngle;
float AzimuthVector[2];
};
extern sDodgyPencilGlobals gDodgyPencilGlobals;

And this to ‘HandleTouches’ in iosView.cpp (line 577 in 4.25, may have moved since)

	auto& dpg = gDodgyPencilGlobals;

	if (Touch.type == UITouchTypePencil)
	{
		if (Type == TouchEnded) 		dpg.Index = -1;
		else						dpg.Index = TouchIndex;

		dpg.Force = Touch.force;
		dpg.MaxForce = Touch.maximumPossibleForce;
		dpg.AltitudeAngle = Touch.altitudeAngle;
		dpg.AzimulthAngle = [Touch azimuthAngleInView : self];
		auto auviv = [Touch azimuthUnitVectorInView : self];
		dpg.AzimuthVector[0] = auviv.dx;
		dpg.AzimuthVector[1] = auviv.dy;
	}
	else if (dpg.Index == TouchIndex)
	{
		dpg.Index = -1;
	}

and this at the very bottom (past @end) of the same file:

sDodgyPencilGlobals gDodgyPencilGlobals =
{
-1, // Index
};

To use, when you have a finger index in your C++ code, compare it to

gDodgyPencilGlobals.Index

and if it matches, read the rest of the same structure for the pencil variables. It’s kind of hacky but it works, or at least worked perfectly. Our iPad version is on hold until we upgrade the project to UE5.

1 Like