keyword: UE4, Mobile, Joystick, UMG Button, OnClick, OnTouch, OnRelease, Android, 虚拟遥感

Issues

问题1:UMG widget 遮挡 joystick,导致joystick只显示无法使用的问题。
原因:UMG的Canvas Panel组件的Visibility属性被修改了。
解决办法:打开UMG蓝图,设置Canvas Panel的Visibility为:Self Hit Test Invisible。

问题2:joystick摇杆和UMG button在移动端冲突的问题:按住摇杆时,UMG button按了不起作用。
原因:UMG button的Is Focusable属性设置为了true。
解决办法:UMG button的Is Focusable属性设置为false。

问题3:按住摇杆不放,UMG button点击事件中,摇杆的InputValue被引擎值为0,Button Release后InputValue才恢复为原有值。
原因:同上。
解决办法:同上。

问题4:Widget的Visibility属性默认为Self Hit Test Invisible,这样,每当有新的Widget AddToViewport时,当前Widget会被自动隐藏。但是默认的Visibility无法响应Widget之外的鼠标或touch事件(比如一个UButton,如果按住UButton不放,然后鼠标或者手指拖拽到UButton之外,那么当松开鼠标或手指时,该button的Release事件无法响应),但是Visibility属性如果设置成Visible,那么就可以响应,但是当新的Widget添加Viewport时,当前Widget不会自动隐藏。

参考:Virtual Joystick conflicts UMG Buttons
https://answers.unrealengine.com/questions/211064/virtual-joystick-conflicts-umg-buttons.html

以上问题在4.18到4.21版本中验证过,不保证后续新版本仍存在。

Examples

基于HUD实现的技能摇杆系统:SkillJoystick for UE4
缺点:没有UMG Button完善的交互功能,只有拖拽和摇动;
优点:避开了UMG的所有潜规则,且性能远超UMG。

ESlateVisibility

\Engine\Source\Runtime\UMG\Public\Components\SlateWrapperTypes.h

/** Is an entity visible? */
UENUM(BlueprintType)
enum class ESlateVisibility : uint8
{
    /** Default widget visibility - visible and can interact with the cursor */
    Visible,
    /** Not visible and takes up no space in the layout; can never be clicked on because it takes up no space. */
    Collapsed,
    /** Not visible, but occupies layout space. Not interactive for obvious reasons. */
    Hidden,
    /** Visible to the user, but only as art. The cursors hit tests will never see this widget. */
    HitTestInvisible,
    /** Same as HitTestInvisible, but doesn't apply to child widgets. */
    SelfHitTestInvisible
};
How to set visibility of Virtual Joystick at run-time
void APlayerController::SetVirtualJoystickVisibility(bool bVisible);
Assets & Plugins

Easy Joystick. Our mobile virtual joystick system is designed to offer deep customization in joystick layout, size, color, and position.
https://www.unrealengine.com/marketplace/en-US/product/easy-joystick


念念不忘,必有回响。----陈念萱