H
H
HellFingers2020-02-20 19:01:22
C++ / C#
HellFingers, 2020-02-20 19:01:22

How to cast an InputField to a list?

Hello, I'm working on a project in Unity. There are several objects of which input fields are children. Also, by pressing a certain button, these fields can be created inactive in the parent object. It is necessary to go through all parent objects, and throw their child InputField into the list.
I tried to do it through GetComponentsInChildren, but since the input fields have their own child objects, they are also added. Tried to do it through FindWithTag but it does not search for inactive objects. Thanks in advance.
PS When using GetComponentsInChildren, I decided to filter by the name of the input field, as they are defined. But a NullReferenceException is thrown: Object reference not set to an instance of an object. Here is the code:

foreach (Transform elem in BufferOfStart)// BufferOfStart - Transform[] с дочерними элементами
        {
            if(elem.gameObject.name == "InDirField")
            {
                Debug.Log(elem.gameObject);// В консоли unity выводится имя обьекта 
                // ArrayOfStartDirectoriesFieldsInChildrenTransform - итоговый список с полями ввода
                ArrayOfStartDirectoriesFieldsChildrenTransform.Add(elem);//выскакивает ошибка
                Debug.Log(elem);
            }
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
ChessMax, 2020-02-21
@ChessMax

Perhaps ArrayOfStartDirectoriesFieldsChildrenTransformnot created?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question