- Home /
is there a way to acess a fixed joint (or other types) trough its transform (i can only do it for a hinge joint)
i am trying to check if a fixed joint exists on the transform but for some reason in my if statement myvar.fixedjoint (or myvar.Fixedjoint)returns the error 'fixedJoint' is not a member of 'UnityEngine.Transform'
i have tried this with all joint types capitalised or not , only hinge joints work and checking if a transform with a fixed joint has a hinge joint returns false
this is my code as i need it but it doent work
i could use hinge joints instead of fixed and it works but am worried about efficiency and anyway im curious as to why this is
var thisinfo : Transform;
function Start(){ thisinfo = transform;}
function OnCollisionEnter(c : Collision) { if (thisinfo.fixedJoint == null) { var joint = gameObject.AddComponent(FixedJoint); joint.connectedBody = c.rigidbody; } }
Answer by Waz · Jul 04, 2011 at 12:28 PM
You can access any component like this:
if (thisinfo.GetComponent(FixedJoint) == null) ...
Not really necessary to cache if you're only calling on collision enter, but if you do, just store it when you create it and never look it up.
Your answer
![](https://koobas.hobune.stream/wayback/20220612132258im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
if syntax for blank variable. 3 Answers
How do I check if a game object exists? 1 Answer
Check For MissingReferenceException 1 Answer
empty component var 1 Answer
How do I check if all objects in an array are destroyed? 2 Answers