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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

A Little new problem with InputField

Discussion in 'UGUI & TextMesh Pro' started by XperienceGame, Oct 22, 2021.

  1. XperienceGame

    XperienceGame

    Joined:
    Apr 16, 2013
    Posts:
    6
    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 :(
     
  2. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    970
    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.
     
  3. XperienceGame

    XperienceGame

    Joined:
    Apr 16, 2013
    Posts:
    6
    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 :

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class characterCreation : MonoBehaviour
    7. {
    8.     private Vector3 charaPos;
    9.     private Quaternion newRot;
    10.  
    11.     public bool newCharacter;
    12.  
    13.     //Button Selection
    14.     private Button maleSelect;
    15.     private Button femaleSelect;
    16.  
    17.     private bool selected;
    18.  
    19.     // ---- Resources Load Characters -----
    20.     public Object[] charactersSex;
    21.  
    22.     //catalogue modular
    23.     public GameObject[] hair;
    24.     private GameObject[] ebrow;
    25.     public GameObject[] face;
    26.     private GameObject[] fhair;
    27.  
    28.     //scrollbars
    29.     public Scrollbar shair;
    30.     private Scrollbar sebrow;
    31.     public Scrollbar sface;
    32.     private Scrollbar sfhair;
    33.  
    34.     //values Scrollbar
    35.     public int hv;
    36.     public int fv;
    37.     private int ebv;
    38.     private int hfv;
    39.  
    40.     void Start()
    41.     {
    42.         charaPos = GameObject.FindGameObjectWithTag("charaPos").transform.position;
    43.         newRot = Quaternion.Euler(0, 180, 0);
    44.  
    45.         //Load all characterSex
    46.         charactersSex = Resources.LoadAll<GameObject>("_CharacterCreation/Prefabs");
    47.  
    48.         //sexe selection Button
    49.         maleSelect = GameObject.FindGameObjectWithTag("mButton").GetComponent<Button>();
    50.         femaleSelect = GameObject.FindGameObjectWithTag("fButton").GetComponent<Button>();
    51.  
    52.         maleSelect.onClick.AddListener(maleSelection);
    53.         femaleSelect.onClick.AddListener(femaleSelection);
    54.  
    55.         selected = false;
    56.         reloadAll();
    57.         newCharacter = false;
    58.     }
    59.  
    60.     void reloadAll()
    61.     {
    62.         //modular objects location
    63.         hair = GameObject.FindGameObjectsWithTag("hair");
    64.         face = GameObject.FindGameObjectsWithTag("face");
    65.         ebrow = GameObject.FindGameObjectsWithTag("eyebrow");
    66.  
    67.         if(!GameObject.FindGameObjectWithTag("femaleCharacter"))
    68.             fhair = GameObject.FindGameObjectsWithTag("facialHair");
    69.  
    70.         //scrollbars location
    71.         shair = GameObject.FindGameObjectWithTag("shair").GetComponent<Scrollbar>();
    72.         sebrow = GameObject.FindGameObjectWithTag("sebrow").GetComponent<Scrollbar>();
    73.         sface = GameObject.FindGameObjectWithTag("sface").GetComponent<Scrollbar>();
    74.  
    75.         if (!GameObject.FindGameObjectWithTag("femaleCharacter"))
    76.             sfhair = GameObject.FindGameObjectWithTag("sfhair").GetComponent<Scrollbar>();
    77.  
    78.         //scrollbar nstep
    79.         shair.numberOfSteps = hair.Length;
    80.         sebrow.numberOfSteps = ebrow.Length;
    81.         sface.numberOfSteps = face.Length;
    82.  
    83.         if (!GameObject.FindGameObjectWithTag("femaleCharacter"))
    84.             sfhair.numberOfSteps = fhair.Length;
    85.     }
    86.  
    87.     void Update()
    88.     {
    89.         if (newCharacter)
    90.         {
    91.             reloadAll();
    92.             newCharacter = false;
    93.         }
    94.  
    95.         //scrollbar Value Update
    96.         hv = (int)(shair.value * hair.Length);
    97.  
    98.         if (hv == hair.Length)
    99.             hv = hair.Length - 1;
    100.  
    101.         fv = (int)(sface.value * face.Length);
    102.  
    103.         if (fv == face.Length)
    104.             fv = face.Length -1;
    105.  
    106.         ebv = (int)(sebrow.value * ebrow.Length);
    107.      
    108.         if (ebv == ebrow.Length)
    109.             ebv = ebrow.Length - 1;
    110.  
    111.         if (!GameObject.FindGameObjectWithTag("femaleCharacter"))
    112.         {
    113.             hfv = (int)(sfhair.value * fhair.Length);
    114.  
    115.             if (hfv == fhair.Length)
    116.                 hfv = fhair.Length - 1;
    117.  
    118.         }
    119.  
    120.         //maskAll
    121.         for (int i =0; i <hair.Length; i++)
    122.         {
    123.             hair[i].SetActive(false);
    124.         }
    125.  
    126.         hair[hv].SetActive(true);
    127.  
    128.         //------------
    129.         for (int i = 0; i < face.Length; i++)
    130.         {
    131.             face[i].SetActive(false);
    132.         }
    133.  
    134.         face[fv].SetActive(true);
    135.  
    136.         //-------------
    137.         if (!GameObject.FindGameObjectWithTag("femaleCharacter"))
    138.         {
    139.             for (int i = 0; i < fhair.Length; i++)
    140.             {
    141.                 fhair[i].SetActive(false);
    142.             }
    143.  
    144.             fhair[hfv].SetActive(true);
    145.         }
    146.  
    147.  
    148.         //-------------
    149.         for (int i = 0; i < ebrow.Length; i++)
    150.         {
    151.             ebrow[i].SetActive(false);
    152.         }
    153.  
    154.         ebrow[ebv].SetActive(true);
    155.  
    156.         // -------- Check sex selected --------
    157.         if (!selected)
    158.         {
    159.             maleSelect.Select();
    160.             maleSelect.interactable = false;
    161.             femaleSelect.interactable = true;
    162.  
    163.             if (!GameObject.FindGameObjectWithTag("maleCharacter"))
    164.             {
    165.                 Destroy(GameObject.FindGameObjectWithTag("femaleCharacter"));
    166.                 Instantiate(charactersSex[1], charaPos, newRot);
    167.                 newCharacter = true;
    168.             }
    169.  
    170.         }
    171.         else if(selected)
    172.         {
    173.             femaleSelect.Select();
    174.             femaleSelect.interactable = false;
    175.             maleSelect.interactable = true;
    176.  
    177.             if (!GameObject.FindGameObjectWithTag("femaleCharacter"))
    178.             {
    179.                 Destroy(GameObject.FindGameObjectWithTag("maleCharacter"));
    180.                 Instantiate(charactersSex[0], charaPos, newRot);
    181.                 newCharacter = true;
    182.             }
    183.         }
    184.  
    185.     }
    186.  
    187.     void maleSelection()
    188.     {
    189.         if (!selected)
    190.         {
    191.             maleSelect.Select();
    192.         }
    193.         else
    194.         {
    195.             maleSelect.Select();
    196.             selected = false;
    197.         }
    198.  
    199.     }
    200.  
    201.     void femaleSelection()
    202.     {
    203.         if (selected)
    204.         {
    205.             femaleSelect.Select();
    206.         }
    207.         else
    208.         {
    209.             femaleSelect.Select();
    210.             selected = true;
    211.         }
    212.     }
    213. }
    I've something wrong ? Because I don't what see o_O It's because the script access to UI elements ? It's problematic for custom player's name because it's a RPG lol
     
  4. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    970
    Oh, this is using UGUI Component, this is the UI Toolkit forum. I'll move this thread to the proper forum. Sorry about that!
     
  5. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    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.