Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by SimRuJ · May 12, 2021 at 12:50 PM · textmeshonclick

How do you register a click on a TMP text?

Hello everyone,

I've got a regular TextMeshPro text GameObject (stand-alone, without canvas) and want to write to console when someone clicks on it. I already added a "ClickText" script to the GO but can't get any of the functions to trigger. What I've tried so far:

  1. Implement "IPointerClickHandler" in "ClickText", with "OnPointerClick(PointerEventData eventData)" - didn't work.

  2. Add a "PointerClicker" event trigger for the GO (through the editor) and set it to call "ClickText.onClick()" function - didn't work.

  3. "OnMouseDown" - didn't work (only meant for GameObjects with an actual collider afaik)

How do you register clicks on a TMP text (Unity 2021.1.6f1)?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Kheremos · Dec 04, 2021 at 09:05 PM

Hello, I'm assuming you've moved past this, but in case someone else stumbles upon this search result (which is high on the list) one way to do this is by adding an Event Trigger component to your text object (via the GUI). Then click [Add New Event Type] and select PointerClick. Then you just populate the trigger conditions and method(s) as usual.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SimRuJ · Dec 06, 2021 at 09:36 AM 0
Share

As mentioned in the question, the "Event Trigger" route didn't work - I just tested it again and it still doesn't. Yes, there's an active EventSystem in the scene but I'm not sure what else I need. I'm now using "OnMouseDown" with a BoxCollider. Btw, I also posted a thread in the forums, which might be the better place if anyone wants to "investigate" things.

avatar image Kheremos SimRuJ · Mar 02 at 03:56 PM 0
Share

I'm sorry, I promise I read the question, but only the first time I came to this page. After that I went and tinkered, and your #2 (that didn't work for you) worked for me. Was this happening to you even in an empty project? I'll check the Unity forums thread to see if there are further updates. Also, I said put it on the text object, you said you put it on the GO, that may make a difference?

avatar image SimRuJ Kheremos · Mar 14 at 10:31 AM 0
Share

I replied in the forum thread.

But yes, I added everything (including the mesh collider) directly to the 3D text (= its GO), not a parent or child. No, I haven't tested it in an empty project yet but I'm not sure why it would work there and not in my current project anyway.

avatar image
0

Answer by SimRuJ · Dec 06, 2021 at 09:45 AM

The only way that (currently) works I've found to be OnMouseDown() but only if you add a collider (BoxCollider is probably the simplest, no need to tick "Is Trigger") to the GameObject.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by spaceman8 · Mar 01 at 10:55 AM

You can add a Button component and remove the Image if you simply want an invisible clickable area with events. This will use the UI's rectTransform to determine the boundaries for click events.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SimRuJ · Mar 14 at 10:35 AM 0
Share

A (TMP) button requires a canvas, a stand-alone 3D TMP text doesn't.

Edit: Sorry, misunderstood you. I just added a "Button" component to the text directly (which automatically set the "target graphic" to the text) and set its "OnClick" but it doesn't trigger either.

avatar image spaceman8 SimRuJ · Mar 14 at 04:09 PM 0
Share

Oh yes, sorry I should have read your question more closely. Without a canvas I believe you will need to setup your own ray caster and collider test and do this logic yourself.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

162 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Creating OnMouseDown() action An object that contains 5 TextMeshPro in an horizontal layout group. 0 Answers

How does one Animate an alpha change (so fade) for a Textmesh? 0 Answers

How to make a TextMeshProUGUI shrink over time? 0 Answers

These error are coming i don't know how to solve 1 Answer

how to change width of box when input sprites? TextMeshPro.preferedWidth doesn't work well with sprite assets, is there any solution for that? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges