- Home /
How do I select a joint component from a GameObject that has multiple joint components?
I have a complex rig setup using configurable joint. In my case I have 2 configurable joint components in a GameObject. I just want to make a reference to one of them. How can I accomplish this?
When I use gameObject.GetComponent();
, there is no way to tell which joint I am getting.
Answer by Kiwasi · Sep 28, 2014 at 11:36 PM
Multiple solutions come to mind. Pick one that matches your game structure.
Use multiple children objects, and attach the joints to them. Then you can reference each joint by the name or tag of its GameObject.
If you are using a prefab you can configure these via the inspector.
If you are adding the joints via script you can store a reference.
There is also GetComponents that will return an array with all of the components. You can iterate through the array and grab the component you want by inspecting its properties.