Is there a way to set up auto complete for a text input. To put in a list of words or phrases and when some of it was typed in sugest it.
I don’t know of a way in Unity with out hard coding it yourself. If you make it your self, feel free to sell it on the asset store for 5 - 10 dollars.
![]()
Bennet
Here example… free ![]()
usingUnityEngine;
usingSystem.Collections;
usingSystem.Collections.Generic;
public class AutocompleteSearch : MonoBehaviour {
List words = newList();
string myText = “”;
publicTextMesh textAutocomplete;
void Start () {
words.Add(“Maria Martinez”);
words.Add(“Maria Gonzales”);
words.Add(“Mario Gonzales”);
}
void OnGUI () {
string oldString = myText;
myText = GUI.TextField(newRect(10, 10, 200, 20), myText);
if (!string.IsNullOrEmpty(myText) && myText.Length > oldString.Length) {
List found = words.FindAll( w => w.StartsWith(myText) );
if (found.Count > 0){
//myText = found[0];
textAutocomplete.text = found[0];
print (found.Count);
}
}
}
}
It would be nice if people actually thanked others for their gracious (and free) assistance here. I had the same issue and Ing Rico’s script really helped me out. Thank you very much for it.
Here is my code you can edit it and enjoy keep coding by kunal Paul
*)what I m doing here is searching from the input field and displaying matching result by comparing it with the list
special thank to log rico.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEngine.UI;
public class Myautocomplete : MonoBehaviour {
List Name= new List(){“hairy”,“harsh”,“hussain”,“huttry”,“habibi”,“hemlet”,“kunal”,“krunal”,“pravin”,“pal”,“paul”,“parkash”,“patharwal”,“pandey”};
public GameObject PanelToHoldTheSearchButton; //this is just the panel to hold the insatiate button.
public InputField inputfield; //this is the input field where you will enter the search string to search.
List found0; // this is the first filter result from your first string word
bool onetime; //so that the process stop after one search.
bool twotime; //so that the process stop after one search.
void Start () {
onetime = true;
twotime = true;
}
void Update () {
if (inputfield.text == “”) {
//making this because if we go to blank inputfield the to the search result stay and if we are entering the world then to it is not proseed due to onetime=false;
GameObject[ ] destroy = GameObject.FindGameObjectsWithTag (“Player”);
for (int i = 0; i < destroy.Length; i++) {
Destroy (destroy );
}
onetime = true;
}
if (inputfield.caretPosition == 1) {
//destroying the gameobject as it created multiple
if (twotime == false) {
GameObject[ ] destroy = GameObject.FindGameObjectsWithTag (“Player”);
for (int i = 0; i < destroy.Length; i++) {
Destroy (destroy );
}//for loop
}//if loop
found0=Name.FindAll(p=>p.StartsWith(inputfield.text));
if (onetime == true) {
for (int i = 0; i <= found0.Count - 1; i++) {
GameObject btn = Instantiate (Resources.Load (“PanelButton/SearchResultButton”))as GameObject;
btn.transform.SetParent (PanelToHoldTheSearchButton.transform, false);
btn.name = found0 ;
//btn.GetComponent ().onClick.AddListener (stinputfield.swaptext);
btn.GetComponentInChildren ().text = found0 ;
onetime = false;
twotime = true;
}//for loop
}//if loop
}//if main loop
if (inputfield.caretPosition == 2) {
if (onetime == false) {
GameObject[ ] destroy = GameObject.FindGameObjectsWithTag (“Player”);
for (int i = 0; i < destroy.Length; i++) {
Destroy (destroy );
}onetime = true;
}
string TwoWords = inputfield.text;
string SecondWord = TwoWords.Substring (1, TwoWords.Length - (TwoWords.Length - 1));
Debug.Log (SecondWord);
if (twotime == true) {
for (int i = 0; i < found0.Count; i++) {
Debug.Log (found0 .Substring (1, found0 .Length - (found0 .Length - 1)));
if (SecondWord == found0 .Substring (1, found0 .Length - (found0 .Length - 1))) {
GameObject btn = Instantiate (Resources.Load (“PanelButton/SearchResultButton”))as GameObject;
btn.transform.SetParent (PanelToHoldTheSearchButton.transform, false);
btn.name = found0 ;
//btn.GetComponent ().onClick.AddListener (stinputfield.swaptext);
btn.GetComponentInChildren ().text = found0 ;
twotime = false;
}// if loop
}// for loop
}//if loop
}// main start if loop
}// upadate loop
}// main loop
here is my version,feel free to use it.
Blog : Unity3D Editor TextField AutoCompelete – Clonefactor
it also provided a option to enable & disable the fuzzy matching based on this article :
Generic Levenshtein edit distance with C# | Microsoft Learn

Nice blog, man**!**
Thank you all!
Very useful!
Hi,
Kindly give step for “PanelButton/SearchResultButton” to assign on the script.
Important Links.
-
Bitbucket (AutoCompleteComboBox)
==>> Bitbucket -
AutoCompleteTextField free On Asset Store
==>> AutoComplete Popup | GUI Tools | Unity Asset Store