Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Putting a script that implements IPointerDownHandler on a Text means you can't type there?

Discussion in 'UGUI & TextMesh Pro' started by jerotas, Dec 4, 2014.

  1. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    How do I fix that? Disabling the script makes it visually click again (interactable). Very weird. I took a quick look at the parameter PointerEventData and didn't see anything I could set to fix it?

    Something similar happens if I put that script on a text field (can't type there anymore until I disable or remove the script).

    I'm using this asset from the store by Unity for testing: https://www.assetstore.unity3d.com/en/#!/content/25468

    My class implements IPointerDownHandler and has a method like this:

    Code (csharp):
    1.  
    2. public void OnPointerDown (PointerEventData data) {
    3.    Debug.Log("down");
    4. }
    5.  
     
    Last edited: Dec 4, 2014
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,181
    I just did this:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.EventSystems;
    4.  
    5. public class TestScript : MonoBehaviour, IPointerDownHandler
    6. {
    7.     // Trigger all registered callbacks.
    8.     public virtual void OnPointerDown(PointerEventData eventData)
    9.     {
    10.         Debug.Log ("down");
    11.     }
    12. }
    13.  
    14.  
    And it works properly when attached to a button.
     
  3. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    Thanks for the response. Ok I checked again and right, that does work. It looks like what I actually did was: there's a child game object of the Button game object that has a Text component. Now if you put that same script on the game object with the Text component, you can no longer click there to type things. That seems to go for all Text components regardless of hierarchy.

    Is that a bug, or expected behavior? Is there something I can do to still type there? Renaming the thread for the real issue.
     
  4. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,181
    It's expected behaviour. The click goes to the element MOST valid to receive it. In your case it's the text as it can handle the click. If the text can't handle the click we look UP the tree for the thing that is valid to handle it.
     
  5. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    I don't think you understand what is happening. I said if I put a script on a Text game object, you can't actually type in that text component anymore. The script with IPointerDownHandler prevents you from being able to type in the text field. That doesn't seem normal to me.
     
  6. Sbizz

    Sbizz

    Joined:
    Oct 2, 2014
    Posts:
    250
    @jerotas: can you show me your hierarchy ? I don't really understand what you wanna do.

    I mean, you're talking about the Text component and typing on that component.. but you can't do that, Text component is just a "label". You should use InputField component.

    Maybe I'm missing something, this is why I need to see your project hierarchy.
     
  7. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    Ok, you're right about that part (Input Field). The Text is just the watermarked "Type something..." text. Here's a screenshot. Notice I have the game object "Text" highlighted in the Hierarchy. If I put a script on it that implements IPointerDownHandler, you can no longer click on its parent (InputArea) and type anything. I'm not sure why you would want to put a script on the Text game object, but it still seems like a bug, not being able to type into the Input Field. Is it?

    If I put that same script on the Input Field instead, I can click there and type. Which would suit my purposes fine. I'm just worried that one of my users may put a script on the wrong game object and wonder why they can't type any more.

    upload_2014-12-5_18-19-57.png
     
  8. Sbizz

    Sbizz

    Joined:
    Oct 2, 2014
    Posts:
    250
    Do you have the last version of Unity 4.6 ? Because it works well on my computer:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.EventSystems;
    3. using System.Collections;
    4.  
    5. public class mytest : MonoBehaviour, IPointerDownHandler {
    6.     public void OnPointerDown(PointerEventData data) {
    7.         Debug.Log("CLICK AND TYPE");
    8.     }
    9. }
    10.  
    unityType.jpg
     
  9. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    I have the *only* released version of 4.6 (unless there has been a hotfix I didn't know about). Not the beta. It definitely doesn't work on my machine. Click on the input field, type, nothing happens. Disable the script, it works. I can't see your Hierarchy so it may not be the same test. I was using that example UI project you can download. It isn't just a Text, but has an input as a parent and some other stuff.
     
  10. Sbizz

    Sbizz

    Joined:
    Oct 2, 2014
    Posts:
    250
    You can see my hierarchy on the screen (bottom right). I'm gonna try on the UI Project, I need to download it.
     
  11. Sbizz

    Sbizz

    Joined:
    Oct 2, 2014
    Posts:
    250
    Okay, got it. I guess there is a bug in their scene. If can only type "a" in the input. I can't explain why :/

    Maybe the bug comes from their Navigation system (sometime it focuses on another UI element (the slider, the scrollview and the large text input)).
     
  12. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    Ok cool, I'm not crazy :) Thanks.