instantiated child couldnt access parents components

hi, i have a gameobject(child1) who is child of parent(parent1). this parent object has got another parent(mainparent). when i try to access mainparent components from child1 my script was working. but after that i wanted to insantantiate that child1 for populate objects. i prepared prefab of child1 and instantiated. after instantiation, i was set parent of child1(clone) to parent1. and again try to access mainparent components via child1(clone) it wasnt work. i can access parent1’s components from child1(clone) but cant access mainparent’s components. and original child1s are working perfectly. they can still access both parents components. where is the problem?

Did you double check the instantiated prefab lies under the parent gameobject ? If it is not you can not access the parent features like:

transform.parent…

You should either use GameObject.FindGameObjectWithTag() or create the whole mainparent/parent/child as a prefab, depending on your requirement.

Hope it helps!