- Home /
How can I determine the parent of a component?
I need to find out (with Javascript) how to determine the parent object that a Skinned Mesh Renderer component is attached to.
I'm instantiating some character prefabs and the Skinned Mesh Renderer isn't always attached to the same bone in the character heirarchy, so I want to be able to determine which bone object actually contains the Skinned Mesh Renderer.
I can find it no problem with "characterObject.GetComponentInChildren(SkinnedMeshRenderer);" but once I do that I need to know which actual bone in the character contains that component.
Answer by Jessy · Sep 25, 2010 at 09:20 PM
SkinnedMeshRenderer inherits from Renderer, which inherits from Component. As such, this is easy:
http://unity3d.com/support/documentation/ScriptReference/Component-gameObject.html
At least, I think that's what you're talking about. If you actually want a parent object, and not the Game Object that has the Skinned Mesh Renderer attached, then you can use
http://unity3d.com/support/documentation/ScriptReference/Transform-parent.html
Answer by Tzan · Sep 25, 2010 at 08:45 PM
So you need the GameObject that holds the Component you can find.
http://unity3d.com/support/documentation/ScriptReference/Component.html
So from Component you can get the transform for the GO.
comp.transform
http://unity3d.com/support/documentation/ScriptReference/Transform.html
From the Transform you can access the entire GO
comp.transform.name // etc
I havent tried it. I'm assuming getting the name of the transform would get you the name of the GO. Maybe comp.name gets you the name of the GO.
$$anonymous$$y god, is it really so hard to just try it ins$$anonymous$$d of babbling about whether it works?? :-P
(Yes, it works: http://unity3d.com/support/documentation/ScriptReference/Object-name.html)
While you were babbling about me babbling I was trying it out. :) seems that all .name calls return the GO name. But I'm not entirely sure what he is looking for. I dont do character anim yet. Its best if he reads through those links.
But thanks for the -1 anyway, having a bad day? :)
No, I'm always like this. ;-) Don't post such terrible junk!
It couldnt be all that bad since you agreed that it works :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613073901im_/https://answers.unity.com/themes/thub/images/avi.jpg)