Reputation: 67
I'm trying to use GetComponent
for inactive gameObject which is called "Character":
testingCollison test;
void Start()
{
GameObject inter = GameObject.Find("Character");
test = inter.GetComponent<testingCollison>();
}
but it is giving this error:
it is pointing to this line : test = inter.GetComponent<testingCollison>();
I tried replacing GetComponect
with GetComponentInChildren
as I found it as a solution when I looked up this issue, but it didn't make any difference.
How can I use getComponent of inactive object?
Upvotes: 0
Views: 2718
Reputation: 963
GetComponent works on inactive GameObjects.
The GameObject.Find however can only return active GameObjects. Inactive GameObjects cannot be found.
Possible solutions:
Upvotes: 1