NullReference with transform.Find();

Hello,

i have an issue with “transform.Find()”. At first i want to tell you, that i’m very new to Unity and programming, so please forgive me if my question might Sound dumb. I already tried to find my error through a Google search, but None of the found Topics was able to really help me.

To make a bit clearer what i’m talking about, here’s the row from my program i’m talking about

	cameraHeadTransform = transform.Find("CameraHead");

i understand, that i assign a value to “cameraHeadTransform”, the value is defined bi "transform.Find(“CameraHead”);. The issue is: “transform.Find(“CameraHead”)” always Returns “null” and thus all following scripts acessing “cameraHeadTransform” result in an null reference exception.

Now the fun part is as follows:

If i use “transform.Find(”/Player/CameraHead")" the script does work (!) without an error. But i do not understand why it is as it is. The “Prefab” is called “Player”, and it contains “CameraHead”, the Problem is, i want to use the same scipt for other prefabs, that have different names, and so i cannot assign “/Player” into the script at all. I would just prefer to use it as “Search if the parent has a child named “CameraHead””.

Any hints on what i’m doing wrong or how to solve it?

Problem solved already.

The solution was: I accidentially added the same script to another child, that again didnt contain any subchilds of Name “CameraHead”. Simple fault leading to big issues.

Thanks!