playMaker

Author Topic: Custom Action Help! - "IsPointerOverGameObject" and Unity 5 UI  (Read 9082 times)

polygon

  • Playmaker Newbie
  • *
  • Posts: 18
Hi Playmakers,

I'm creating some custom actions for a project that I'm working on and I need to determine if a touch input (touch began) hits a UI element or not. I found out that this works with "IsPointerOverGameObject" and wrote a custom action which you can see here:
Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.

using System;
using UnityEngine;
using UnityEngine.EventSystems;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Device)]
[Tooltip("Sends an Event if an Object gets touched and another Event if the UI gets touched.")]
public class TouchEventPF : FsmStateAction
{


[ActionSection("Events")]

[Tooltip("Event to send on touch began.")]
public FsmEvent touchObject;

[Tooltip("Event to send on canvas touch.")]
public FsmEvent touchCanvas;

[ActionSection("Store Results")]

[UIHint(UIHint.Variable)]
[Tooltip("Store the fingerId of the touch.")]
public FsmInt storeFingerId;

private UnityEngine.EventSystems.EventSystem _eventSystem;

public override void Reset()
{
touchObject = null;
touchCanvas = null;

storeFingerId = null;
}

public override void OnEnter ()
{
_eventSystem = GameObject.Find("EventSystem").GetComponent<EventSystem>();
Debug.Log (_eventSystem);
}

public override void OnUpdate()
{

if (Input.touchCount > 0)
{
foreach (var touch in Input.touches)
{

storeFingerId.Value = touch.fingerId;

if (_eventSystem.IsPointerOverGameObject())

{
Fsm.Event(touchCanvas);
Debug.Log ("Touch Canvas!");
}

else
{
Fsm.Event(touchObject);
}

}
}
}
}
}

This works well with Unity Remote (Android) but it doesn't work on the device after building and running the app and the touch goes right trough the UI.

After some research on the web I found this solution for the problem:

http://gamedev.stackexchange.com/questions/90196/how-to-detect-that-user-has-touched-ui-canvas-in-unity-4-6

Obviously the problem is that "On Mobile you need to need pass Touch.fingerId as parameter into EventSystem.IsPointerOverGameObject(int pointerID)" as stated in this forum post.

Sounds logical but I can't get it to work if I change my code from

if (_eventSystem.IsPointerOverGameObject())

to

if (_eventSystem.IsPointerOverGameObject(touch.fingerId))

With the change it doesn't work in any environment: not in the unity remote and not on the device itself :-(

Can you please help me? This drives me crazy and I need it to continue the work on my project :(

Thanks and best regards,
polygon
« Last Edit: March 20, 2015, 07:02:02 PM by polygon »

doppelmonster

  • Full Member
  • ***
  • Posts: 157
    • Grinder Games
Re: Custom Action Help! - "IsPointerOverGameObject" and Unity 5 UI
« Reply #1 on: March 23, 2015, 03:19:25 AM »
Hi,
I am sitting in the same boat:
http://hutonggames.com/playmakerforum/index.php?topic=9705.msg46343#msg46343

The only solution that works so far is:

Quote
The actions are working on touch devices if you enable  "Allow Activation On Mobile Device" but you have to disable the "Touch Input Module" Component on the EventSystem at the same time!

Following this discussion:
http://forum.unity3d.com/threads/standalone-input-module-touch-input-module-behavior-difference.265309/


But then my gui touches are unreliable sometimes they work sometimes not!

So i am still searching for a safe and reliable solution.....

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15496
  • Official Playmaker Support
Re: Custom Action Help! - "IsPointerOverGameObject" and Unity 5 UI
« Reply #2 on: May 12, 2015, 02:59:11 AM »
Hi,

 Is it still doing this with the latest patches from Unity?

If you still have this behavior, I'll have a proper look. I did found some corner cases I submitted to Unity, but haven't double checked on them. In this case it could be some wrong usage and setup tho.

 Bye,

 Jean

doppelmonster

  • Full Member
  • ***
  • Posts: 157
    • Grinder Games
Re: Custom Action Help! - "IsPointerOverGameObject" and Unity 5 UI
« Reply #3 on: May 18, 2015, 01:39:43 AM »
Hi Jean,
I dont have a reliable solution yet and couldnt find a definite answer (or fix log) by Unity or others.

Do you have been able to create a case where its possible to reliable prevent a click through  on mobile devices?

I tried so many things back then. and i am fed up retrying it with every new update of unity. So I wait untill someone else comes up with a definite solution or Unity clearly logs a fix in the release notes....

In the moment I manually pause non gui code manually while gui is in the front for my current game ...

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15496
  • Official Playmaker Support
Re: Custom Action Help! - "IsPointerOverGameObject" and Unity 5 UI
« Reply #4 on: May 20, 2015, 03:59:38 AM »
Hi,

 Yeah, I managed to make that work. I'll do a sample on the Ecosystem. Please bump early next week if I haven't done it.

 Bye,

 Jean

doppelmonster

  • Full Member
  • ***
  • Posts: 157
    • Grinder Games
Re: Custom Action Help! - "IsPointerOverGameObject" and Unity 5 UI
« Reply #5 on: May 21, 2015, 04:49:21 AM »
thanks Jean!

please give a shout here when you have done it. Or tell us what to search for on the ecosystem. With trial and error keywords its hard to know if you put something up...

I really like the idea of the ecosystem  but it would need a proper listing....

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15496
  • Official Playmaker Support
Re: Custom Action Help! - "IsPointerOverGameObject" and Unity 5 UI
« Reply #6 on: May 21, 2015, 06:33:31 AM »
Hi,

 Yeah, I'll make a post and a tweet when done.

 Bye,

 Jean