Attaching a Model to a prefab at runtime

Hi,

I’m not quite sure what i’m doing wrong, but I have a character Prefab ( which is just a model with a script ), and i’m trying to attach another prefab (a Ski model) to it’s foot. In my manager script ( which is definitely running ), i use the following code

Transform character = (Transform)Object.Instantiate(PrefabCharacter, point, Quaternion.identity);

Transform leftFoot = character.transform.FindChild("l_toe");

Transform leftSki = (Transform)Object.Instantiate(SkiModel, point, Quaternion.identity);

leftSki.parent = leftFoot; // 1
//leftSki.parent = character.transform; // 2
leftSki.localPosition = Vector3.zero;
leftSki.localRotation = Quaternion.identity;

The weird thing is that if i replace (1) with (2), it sort of works - the ski attaches somewhere on the character who is walking around, despite it not being attached in the correct position. What worries me, is that if i do a

Debug.Log("Blah: " + leftSki.position);

under that code, I get a runtime error saying that get_position could not be accessed. Anyone got any ideas?
Just to cover a few things, i did some debug logging to make sure all those objects are what i’m casting it to, so those assumed casts should be safe.

Thanks in advance

David Goemans

You should use transform.Find to access a child object. Is the foot’s parent the character or is there a hierarchy leading down to the foot? If there is, you will need to supply the “pathname” to reach the foot from the parent as explained on the transform.Find doc page.

Wow, that definitely helps! Why doesn’t FindChild work?
I’m still having serious offset issues though. Is there anything special that has to be done with the exporting process from our artists that you can think of off hand, otherwise i’ll spend a bit of time resolving it.

Thanks!