playMaker

Author Topic: How to Activate a TMP Input Field?  (Read 4773 times)

dubly94

  • Playmaker Newbie
  • *
  • Posts: 4
How to Activate a TMP Input Field?
« on: May 07, 2023, 09:35:18 AM »
Hello everyone,

I'm looking for an action to activate a TMP Input Field. This action focuses/activates the input field, allowing input to be typed directly into it without requiring a click on the field. Currently, such an action is only available for the UGUI Input Field, namely "UI Input Field Activate".

Is there a workaround or something I'm missing?
I also can't seem to find anything on the Ecosystem.

Thanks in advance.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: How to Activate a TMP Input Field?
« Reply #1 on: May 07, 2023, 05:32:49 PM »

BrushMain

  • Playmaker Newbie
  • *
  • Posts: 3
Re: How to Activate a TMP Input Field?
« Reply #2 on: May 07, 2023, 10:43:08 PM »
I also have the same issue. I think I found a way around it but I am a complete noob so I am not sure if it’s the proper way to solve it.
What I did was drag the “TextMesh Pro – Input field” property into the needed state. I chose ScriptControl – Call Method. Then in “Method” I chose “void ActivateInputField ()”.
When that state is active the input field automatically activates without having to click on it.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: How to Activate a TMP Input Field?
« Reply #3 on: May 08, 2023, 07:10:31 AM »
Hi.
You should avoid using Call Method and Get / Set Properties

They are suing mirroring, there for they are slow.
Also when building you might need to use Linker Wizard to ensure them to work properly

dubly94

  • Playmaker Newbie
  • *
  • Posts: 4
Re: How to Activate a TMP Input Field?
« Reply #4 on: May 08, 2023, 08:00:45 AM »
Hi.
You can find textmesh actions here :
https://hutonggames.com/playmakerforum/index.php?topic=15008.0

I have the TMP Actions installed in my project. However, there doesn't seem to be an action to activate TMP Input Fields.

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 256
Re: How to Activate a TMP Input Field?
« Reply #5 on: May 08, 2023, 08:55:36 AM »
I also have the same issue. I think I found a way around it but I am a complete noob so I am not sure if it’s the proper way to solve it.
What I did was drag the “TextMesh Pro – Input field” property into the needed state. I chose ScriptControl – Call Method. Then in “Method” I chose “void ActivateInputField ()”.
When that state is active the input field automatically activates without having to click on it.
can make a custom action out of this easily. I’ll look at it later today if I get the chance.

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 256
Re: How to Activate a TMP Input Field?
« Reply #6 on: May 08, 2023, 02:39:59 PM »
Try this action:

Code: [Select]
using UnityEngine;
using TMPro;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory("TextMesh Pro UGUI Basic")]
    [Tooltip("Activate or de-activate the Input Field of a Textmesh Pro component")]
    public class ActivateTextmeshProUGUIInputField : FsmStateAction
    {
        [RequiredField]
        [CheckForComponent(typeof(TextMeshProUGUI))]
        [Tooltip("Textmesh Pro component is required.")]
        public FsmOwnerDefault gameObject;

        [Tooltip("If TRUE activates the TMP Input Field. If FALSE de-activates it.")]
        public FsmBool activateInputField;

        private TMP_InputField _inputField;

        public override void Reset()
        {
            gameObject = null;
            activateInputField = false;
        }

        public override void OnEnter()
        {
            _inputField = Fsm.GetOwnerDefaultTarget(gameObject).GetComponent<TMP_InputField>();

            DoInputFieldActivationChange();

            Finish();
        }

        void DoInputFieldActivationChange()
        {
            if (_inputField == null)
            {
                Debug.LogError("No Textmesh Pro component was found on " + gameObject);
                return;
            }

            if (activateInputField.Value)
            {
                _inputField.ActivateInputField();
            }
            else
            {
                _inputField.DeactivateInputField();
            }
           
        }
    }
}
File attached to this post so you just can easily drag and drop it into your project's asset folder.

Let me know if this works as I haven't tested it.

IMPORTANT: New version in my next post! Don't use this one.
« Last Edit: May 10, 2023, 04:55:58 PM by Christoph »

BrushMain

  • Playmaker Newbie
  • *
  • Posts: 3
Re: How to Activate a TMP Input Field?
« Reply #7 on: May 10, 2023, 02:31:47 PM »

Let me know if this works as I haven't tested it.

Edit: actually messed up before, now it should work well. Download again if you already downloaded...

Just tried it and for some reason it tells me that the GameObject requires TMPro.TextMeshProUGUI but it seems to work anyways. Thanks for that, I appreciate it!

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 256
Re: How to Activate a TMP Input Field?
« Reply #8 on: May 10, 2023, 04:54:01 PM »
Sorry for that, here's the corrected action. Just replace the old one and you should be good to go.  :)

Code:
Code: [Select]
using UnityEngine;
using TMPro;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory("TextMesh Pro UGUI Basic")]
    [Tooltip("Activate or de-activate the Input Field of a Textmesh Pro component")]
    public class ActivateTextmeshProUGUIInputField : FsmStateAction
    {
        [RequiredField]
        [CheckForComponent(typeof(TMP_InputField))]
        [Tooltip("Textmesh Pro component is required.")]
        public FsmOwnerDefault gameObject;

        [Tooltip("If TRUE activates the TMP Input Field. If FALSE de-activates it.")]
        public FsmBool activateInputField;

        private TMP_InputField _inputField;

        public override void Reset()
        {
            gameObject = null;
            activateInputField = false;
        }

        public override void OnEnter()
        {
            _inputField = Fsm.GetOwnerDefaultTarget(gameObject).GetComponent<TMP_InputField>();

            DoInputFieldActivationChange();

            Finish();
        }

        void DoInputFieldActivationChange()
        {
            if (_inputField == null)
            {
                Debug.LogError("No Textmesh Pro Input Field was found on " + gameObject);
                return;
            }

            if (activateInputField.Value)
            {
                _inputField.ActivateInputField();
            }
            else
            {
                _inputField.DeactivateInputField();
            }
           
        }
#if UNITY_EDITOR
        public override string AutoName()
        {
            return (activateInputField.Value ? "Enable " : "Disable ") + ActionHelpers.GetValueLabel(Fsm, gameObject);
        }
#endif
    }
}


BrushMain

  • Playmaker Newbie
  • *
  • Posts: 3
Re: How to Activate a TMP Input Field?
« Reply #9 on: May 10, 2023, 05:37:28 PM »
Sorry for that, here's the corrected action. Just replace the old one and you should be good to go.  :)

It’s working beautifully now. Much appreciated, cheers!