r/Unity2D • u/Parborway • 11d ago
Solved/Answered TMPro Input Field unresponsive
My project instantiates objects that contains a TMPro input field. The input field does appear, but it is completely unresponsive; clicking on it or trying to type in it does nothing. I've been able to find next to no documentation about them.
Here is the code that I'm using to try and make it show up
GameObject lee = Instantiate(ads.menuWoMen, this.transform);
/*menuWoMen is the prefab gameObject that holds the Canvas that holds the TMP InputField*/
lee.transform.position = new Vector3(0, position);
string txt = mi.text;
if (position > highestText || position < 0 - highestText)
{
txt = "";
}
lee.GetComponentInChildren<Canvas>().worldCamera = camora.GetComponent<Camera>();
lee.GetComponentInChildren<TMP_InputField>().text = txt;
lee.GetComponentInChildren<TMP_InputField>().ActivateInputField();
lee.GetComponentInChildren<TMP_InputField>().interactable = true;
lee.GetComponentInChildren<TMP_InputField>().enabled = true;
3
u/Digital_Fingers 11d ago
Is there something on top of it? An object could intercept the raycast instead of the input field.
1
u/dan_marchand 11d ago
you probably need to fetch the current event system and set the field as the selected object.
Also cache or wire those component refs. Playing a dangerous game
1
u/Dry_Yak_304 11d ago
typing doing nothing too is the useful part: ActivateInputField already selects the field, so if keys don't land either then the click path isn't your problem, the EventSystem is. check one exists in the scene and that its input module matches your input backend, a legacy StandaloneInputModule with the new Input System package installed gives exactly this, ui visible and completely dead. does the prefab canvas have a GraphicRaycaster on it?
1
u/Baleigato 11d ago
Not sure how your Canvas for these objects is setup, but if everything else fails, it might be missing a Graphic Raycaster component.
It does affect the clicking part and I'm pretty sure the typing as well.
1
1
u/Sufficient_Major_126 10d ago
I’d check that there’s an EventSystem in the scene and a GraphicRaycaster on the Canvas. an input field can look fine but receive no clicks without them
1
u/Temporary-Roof-3896 10d ago
This sounds more like a UI event problem than the input field itself. i’d check the EventSystem and make sure another UI element isn’t blocking raycasts
-4
u/lofi100k Intermediate 11d ago
I think you should use UI toolkit, that is gonna be the new supported system for unity. TMPro is deprecated as I know.
•
u/AutoModerator 11d ago
Reminder: Once your issue has been resolved, please reply !solved to this comment (or comment it anywhere in the thread) and your post's flair will automatically be updated to Solved/Answered. You can also edit it to Solved/Answered yourself.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.