A Little new problem with InputField

Hi,

I’ve write in this forum for my first time, and i’ve uncounter a little problem, and I’ve not seen my problem anywhere. I’m in a dead end.

Let me explain : In a newest scene, InputField work like a charm, but here is, after many hours, I’d created a Character creation scene for my game, and I don’t now why, when I add an InputField just doesn’t work. It’s always interactable, and yes i’ve an EventSystem in my scene.

But the problem is simple : When I click on Inputfield, this is just blinks, and the text cursor appears in 1 ms, it’s blink to. And I don’t no why in this scene InputField blinks when I click on it, and in another scene no.

I’ve no solution :frowning:

Hard to tell what’s going on without having access to the problematic scene, but it looks like something removes the focus from the InputField. I would try to disable running scripts until you find one that causing the issue.

Thanks, It’s solve one part of my problem, if I disable the main script to manage character creation the InputField work great, but when I enable the script, in runtime too, InputField doesn’t work.


My main script of scene :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class characterCreation : MonoBehaviour
{
    private Vector3 charaPos;
    private Quaternion newRot;

    public bool newCharacter;

    //Button Selection
    private Button maleSelect;
    private Button femaleSelect;

    private bool selected;

    // ---- Resources Load Characters -----
    public Object[] charactersSex;

    //catalogue modular
    public GameObject[] hair;
    private GameObject[] ebrow;
    public GameObject[] face;
    private GameObject[] fhair;

    //scrollbars
    public Scrollbar shair;
    private Scrollbar sebrow;
    public Scrollbar sface;
    private Scrollbar sfhair;

    //values Scrollbar
    public int hv;
    public int fv;
    private int ebv;
    private int hfv;

    void Start()
    {
        charaPos = GameObject.FindGameObjectWithTag("charaPos").transform.position;
        newRot = Quaternion.Euler(0, 180, 0);

        //Load all characterSex
        charactersSex = Resources.LoadAll<GameObject>("_CharacterCreation/Prefabs");

        //sexe selection Button
        maleSelect = GameObject.FindGameObjectWithTag("mButton").GetComponent<Button>();
        femaleSelect = GameObject.FindGameObjectWithTag("fButton").GetComponent<Button>();

        maleSelect.onClick.AddListener(maleSelection);
        femaleSelect.onClick.AddListener(femaleSelection);

        selected = false;
        reloadAll();
        newCharacter = false;
    }

    void reloadAll()
    {
        //modular objects location
        hair = GameObject.FindGameObjectsWithTag("hair");
        face = GameObject.FindGameObjectsWithTag("face");
        ebrow = GameObject.FindGameObjectsWithTag("eyebrow");

        if(!GameObject.FindGameObjectWithTag("femaleCharacter"))
            fhair = GameObject.FindGameObjectsWithTag("facialHair");

        //scrollbars location
        shair = GameObject.FindGameObjectWithTag("shair").GetComponent<Scrollbar>();
        sebrow = GameObject.FindGameObjectWithTag("sebrow").GetComponent<Scrollbar>();
        sface = GameObject.FindGameObjectWithTag("sface").GetComponent<Scrollbar>();

        if (!GameObject.FindGameObjectWithTag("femaleCharacter"))
            sfhair = GameObject.FindGameObjectWithTag("sfhair").GetComponent<Scrollbar>();

        //scrollbar nstep
        shair.numberOfSteps = hair.Length;
        sebrow.numberOfSteps = ebrow.Length;
        sface.numberOfSteps = face.Length;

        if (!GameObject.FindGameObjectWithTag("femaleCharacter"))
            sfhair.numberOfSteps = fhair.Length;
    }

    void Update()
    {
        if (newCharacter)
        {
            reloadAll();
            newCharacter = false;
        }

        //scrollbar Value Update
        hv = (int)(shair.value * hair.Length);

        if (hv == hair.Length)
            hv = hair.Length - 1;

        fv = (int)(sface.value * face.Length);

        if (fv == face.Length)
            fv = face.Length -1;

        ebv = (int)(sebrow.value * ebrow.Length);
      
        if (ebv == ebrow.Length)
            ebv = ebrow.Length - 1;

        if (!GameObject.FindGameObjectWithTag("femaleCharacter"))
        {
            hfv = (int)(sfhair.value * fhair.Length);

            if (hfv == fhair.Length)
                hfv = fhair.Length - 1;

        }

        //maskAll
        for (int i =0; i <hair.Length; i++)
        {
            hair[i].SetActive(false);
        }

        hair[hv].SetActive(true);

        //------------
        for (int i = 0; i < face.Length; i++)
        {
            face[i].SetActive(false);
        }

        face[fv].SetActive(true);

        //-------------
        if (!GameObject.FindGameObjectWithTag("femaleCharacter"))
        {
            for (int i = 0; i < fhair.Length; i++)
            {
                fhair[i].SetActive(false);
            }

            fhair[hfv].SetActive(true);
        }


        //-------------
        for (int i = 0; i < ebrow.Length; i++)
        {
            ebrow[i].SetActive(false);
        }

        ebrow[ebv].SetActive(true);

        // -------- Check sex selected --------
        if (!selected)
        {
            maleSelect.Select();
            maleSelect.interactable = false;
            femaleSelect.interactable = true;

            if (!GameObject.FindGameObjectWithTag("maleCharacter"))
            {
                Destroy(GameObject.FindGameObjectWithTag("femaleCharacter"));
                Instantiate(charactersSex[1], charaPos, newRot);
                newCharacter = true;
            }

        }
        else if(selected)
        {
            femaleSelect.Select();
            femaleSelect.interactable = false;
            maleSelect.interactable = true;

            if (!GameObject.FindGameObjectWithTag("femaleCharacter"))
            {
                Destroy(GameObject.FindGameObjectWithTag("maleCharacter"));
                Instantiate(charactersSex[0], charaPos, newRot);
                newCharacter = true;
            }
        }

    }

    void maleSelection()
    {
        if (!selected)
        {
            maleSelect.Select();
        }
        else
        {
            maleSelect.Select();
            selected = false;
        }

    }

    void femaleSelection()
    {
        if (selected)
        {
            femaleSelect.Select();
        }
        else
        {
            femaleSelect.Select();
            selected = true;
        }
    }
}

I’ve something wrong ? Because I don’t what see :eyes: It’s because the script access to UI elements ? It’s problematic for custom player’s name because it’s a RPG lol

Oh, this is using UGUI Component, this is the UI Toolkit forum. I’ll move this thread to the proper forum. Sorry about that!

GameObject.FindGameObjectWithTag is super slow and should not be used in an update loop. I would suggest caching these references or referencing them directly on some public fields. I suspect the overhead added by calling GameObject.FindGameObjectWithTag every frame is the main culprit of this behavior.