Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

ConfigurableJoint created from scipt does't affect anything

Discussion in 'Scripting' started by Adrian, Apr 21, 2008.

  1. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,061
    I'm trying to create a ConfigurableJoint from script. I have a GameObject with a rigidbody and following script is attached:
    Code (csharp):
    1. function Start() {
    2.    joint = gameObject.AddComponent(ConfigurableJoint);
    3.    
    4.    joint.targetPosition = new Vector3(0,0,-1000);
    5.    
    6.    drive = new JointDrive();
    7.    drive.mode = JointDriveMode.Position;
    8.    drive.positionSpring = 100;
    9.    joint.zDrive = drive;
    10. }
    When I start the game, the game objects just sits around doing nothing. It's as if there would be no joint attached to it.

    Strange is, that as soon as I change or select a value in the inspector, the joint jumps into action and the object gets pulled to -1000 as it should.

    Am I not correctly adding the joint? Is there a way I can activate the joint from script?
     
  2. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,061
    Update:

    I tried to come up with some workaround and ended up trying to deactivate and reactivate the game object shortly after as well as instantiate the object and destroy the original.
    Both methods activated the joint but are very unelegant (the first one lets the object disappear shortly and the second appends "(Clone)" to the end of the name of the object).
     
  3. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,061
    Arg, I'm starting to feel lost.

    Code (csharp):
    1. def Start():
    2.     joint = GetComponent(ConfigurableJoint)
    3.     Debug.Log(joint)
    4.     if (joint == null):
    5.         joint = gameObject.AddComponent(ConfigurableJoint)
    6.    
    7.     joint.configuredInWorldSpace = true
    The game object has a rigidbody but no joint attached. When I try to execute this, I get following console messages:

    1. UnityEngine.ConfigurableJoint
    UnityEngine.Debug:Log(Object)
    2. MissingComponentException: There is no 'ConfigurableJoint' attached to the "Ball" game object, but a script is trying to access it.
    You probably need to add a ConfigurableJoint to the game object "Ball". Or your script needs to check if the component is attached before using it.

    It seems like there is some ConfigureableJoint attached to the game object (maybe to every object with a rigidbody?) but if I try to access it, it gives me a missing component exception.

    I guess this could be related to my problem.
     
  4. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,061
    I've submitted my problem as a bug and the unity support was able to reproduce my issue. It's up to be fixed now and it might already be included in the next version.