Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by yathu99 · Dec 29, 2020 at 04:37 PM · uiinputfieldgameobject.find

unable to get InputFiled.text after using multiple GameObject.Find in second script.,Why does InputField.text doesn't returns written text sometimes?

The InputField.text of New_Quest() method of Dialogue_Handler.cs starts returning blank after adding extra GameObject.Find() methods in a second script. Also it doesn't works if i disable the things in chronological order.


Dialogue_menu_handler.cs file:

 using System.Collections.Generic;
 using UnityEngine;
 namespace DialogueSystem
 {
     public class Dialogue_Menu_handler : MonoBehaviour
     {  
         public List<GameObject> gobs = new List<GameObject>();
         void Awake()
         {
             gobs.Add(GameObject.Find("Quest Maker"));
             gobs.Add(GameObject.Find("Dialogue Maker"));
             gobs.Add(GameObject.Find("Option Maker"));
             gobs.Add(GameObject.Find("Dialogue Joiner"));
         }
         void Start() 
         {
             Switch_to_quest_menu();
         }
         public void Switch_to_quest_menu()
         {
             for (int j = 0; j < gobs.Count; j++)
             {
                 if (j != 0)
                 {
                     gobs[j].SetActive(false);
                 }
                 else
                 {
                     gobs[j].SetActive(true);
                 }
             }
         }

Above script is used to switch between UI panels. upon using the switch to quest menu() method in Unity's Awake() method.


Dialogue_handler.cs File:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 namespace DialogueSystem
 {
     public class Dialogue_Handler : MonoBehaviour
     {  
         public List<Quest> All_Quests = new List<Quest>(); 
       /*
         public string Quest = "nothing";
         public InputField DialogID;
         public InputField Actor;
         public InputField DialogueString;
         public Toggle hasOptions;
         public InputField no_op;
         public Toggle hasCode;
         public InputField Code;
         public Dialogue nextNode = null;
         */
         public InputField QuestOrder;
         public InputField QuestName;/*
         public Text QuestLabel;
         public string test = "null";
         */
         public Text QuestResult;
         public void Start()
         {
         /*
             this.DialogID = GameObject.Find("Dialogue ID").GetComponent<InputField>() ;
             this.Actor = GameObject.Find("Actor ID").GetComponent<InputField>() ;
             this.DialogueString = GameObject.Find("Dialogue String").GetComponent<InputField>() ;
             this.hasOptions = GameObject.Find("Option Toggle").GetComponent<Toggle>() ;
             this.no_op = GameObject.Find("How many?").GetComponent<InputField>() ;
             this.hasCode = GameObject.Find("Code Toggle").GetComponent<Toggle>() ;
             this.Code = GameObject.Find("What's the Code").GetComponent<InputField>() ;
 */
             this.QuestOrder = GameObject.Find("Quest Order").GetComponent<InputField>() ;
             this.QuestName = GameObject.Find("Quest Field").GetComponent<InputField>() ;
          //   QuestLabel = GameObject.Find("Quest Name").GetComponent<Text>();
             QuestResult = GameObject.Find("Quest Result").GetComponent<Text>() as Text;
            // this.nextNode = null;
             //Dialogue placeholder = new Dialogue("Quest Name",DialogID, Actor, DialogueString, hasOptions, no_op, hasCode, Code,null);
         }
         public void NewQuest()   // this is called on button click
         {
             Debug.Log(this.QuestName.text);
            //All_Quests.Add(new Quest(int.Parse(QuestOrder.text), QuestName.text));
            // QuestLabel.text = QuestName.text;
         }

Also the Debug.Log(QuestName.text) returns blank again if i initialise the commented data in Dialoge_Handler.cs I have tried to find all gameobjects using GameObject.Find() in unity's in-built Awake method and then disabling the unnecessary panels in UI in the start method so all the Gameobject variables don't give a NullrefrenceException. But upon doing this the inputfield's are not returning any text put into them on runtime.

It only works if all the conditions follow:

  1. If i don't initialize the commented Fields in Dialogue_Handler and not find them in awake or start method.

  2. Using the method switch_to_Quest_menu() in Awake method rather than start method. i am stumped at this as my initial thought was that maybe Gameobject.find is not able to find the gameobjects before i disable them, as a result of which i tried to find all the gameobjects in Awake() and disabled them in Start() but this also didn't work.


    Question:

How could i get the InputField.text to give me runtime value after i initialize and find and store the gameobjects in alist or array?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

192 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

adding a image inside of a muilti line Input Field? 0 Answers

Click UI button while Android keyboard visible 0 Answers

How to disable character movement while editing InputField? 1 Answer

How to insantiate an Inputfield which is populated with numerical values and to add the values of the field to get an output values? 0 Answers

How can I create a Multi line Input Field with Scrollbar? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges