I
I
i__egor2020-07-31 19:36:48
Unity
i__egor, 2020-07-31 19:36:48

Why can't unity see the component?

The slider object contains a slider and two buttons + and -. I'm trying to get a component in it (the same on 2 buttons) on 1 button:
ui_btn = btn1.GetComponent<MyComponentBtn>()
ui_btn1 is null although the component was added before the start.
however, I write:

ui_btn = this.gameObject.GetComponentsInChildren<MyComponentBtn>()[0]

component is located! what could be the issue here?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-07-31
@freeExec

what could be the issue here?

The fact that the object btn1does not have this component.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question