Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Alessandro · Apr 29, 2011 at 07:59 PM · rigidbodyiphonejointconnectedbody

Problem trying to set "connected body" of Fixed Joint via script upon build

Im trying to set the component connected body of a Fixed Joint via script but i get a "connectedBody' is not a member of 'UnityEngine.Component" error when trying to build.

Ive tried something like this:

 obj1.AddComponent("FixedJoint");
var fixJoint = obj1.GetComponent("FixedJoint");
fixJoint.connectedBody = obj2.rigidbody; //ERROR HERE

Then ive put this code to check:

Debug.Log(obj1.GetComponent("FixedJoint"));
Debug.Log(fixJoint.connectedBody);

and ive got:

Obj1 (UnityEngine.FixedJoint)

Obj2 (UnityEngine.Rigidbody)

So everything seems to be working fine on editor mode ?! Any ideas?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Pillgrim · Apr 22, 2014 at 12:59 PM 0
Share

I`ve got the same problem. Every time I try to assign "connectedBody" via code, it says that "Joint2D" can not access non-static member "connectedBody". Is there a way to solve this problem? :c

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by DFLY · Jun 27, 2014 at 03:33 PM

Hi all. I know this is WAY later than the question. But I came across the same problem. I finally stubbled across the answer. For some reason you have to explicitly declare your rigidbody and fixed joint variables at the beginning and NOT within a function. I don't know why but just declare them at the beginning.

Here is my script. It turns children to rigid bodies and fix joins them:

 #pragma strict
 
 private var rig: Rigidbody; // Have to explicitly declare this HERE
 private var fix: FixedJoint;// Also explictly declare this HERE
 
 
 private var lastName: String;
 private var childCount: int;
 
 
 function Start () {
 
 
 
 lastName = "Cube4"; // Just a placeholder. Cube4 is my platform.
 childCount = 0;
 
 for (var child :     Transform in gameObject.transform){
             
         var childName : String = child.name; 
                 
                     
         rig = child.gameObject.AddComponent ("Rigidbody");
                 
                 
         if (childCount != 0){
                 
                     fix = child.gameObject.AddComponent ("FixedJoint");
                     
                        fix.connectedBody = gameObject.Find (lastName).GetComponent ("Rigidbody");
                  }
                 
 Debug.Log ("childName = " + childName);
 Debug.Log ("lastName = " + lastName);
 Debug.Log ("rig = " + rig);
 Debug.Log ("fix = " + fix);
 
  if (childCount != 0) {
  
          Debug.Log ("fix.connectedBody = "  + fix.connectedBody );
          
          }
          
          lastName = childName;
         childCount = childCount +1;
 
 
 
     }
 
 }

 

Hope this helps someone...

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Prances · Feb 10, 2015 at 10:10 PM 0
Share

Thank you DFLY this was a super helpful answer!!

avatar image
0

Answer by sneftel · Apr 29, 2011 at 09:35 PM

Is that C#? If so, then you need to either cast the result of GetComponent, or (better) use the generic version of GetComponent. Incidentally, AddComponent returns the created component, so you can do all that in one step. Like so:

var fixJoint = obj1.AddComponent<FixedJoint>();
fixJoint.connectedBody = obj2.rigidbody;
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Aldwoni_legacy · May 05, 2011 at 01:13 PM 0
Share

it is javascript

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Joint connected body not working 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Multiple connected body on fixed joint 1 Answer

Rigidbody Sliding UP Incline 0 Answers

Force to Velocity scaling? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges