Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Setting ConfigurableJoint.linearLimit.damper from script

Discussion in 'Scripting' started by Brad-Newman, Jul 28, 2013.

  1. Brad-Newman

    Brad-Newman

    Joined:
    Feb 7, 2013
    Posts:
    184
    I'm trying to set the value for ConfigurableJoint.linearLimit.damper via script but I'm getting an error, anyone know how to set this value correctly?

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class SetLinearLimitDamper : MonoBehaviour {
    6.    
    7.     void Start () {
    8.         ConfigurableJoint configurableJointComp = GetComponent<ConfigurableJoint>();
    9.         float linearLimitDamper = configurableJointComp.linearLimit.damper;
    10.         linearLimitDamper = 1f;
    11.         configurableJointComp.linearLimit.damper = linearLimitDamper;
    12.     }
    13. }
    14.  
    Error: SetLinearLimitDamper.cs(10,39): error CS1612: Cannot modify a value type return value of `UnityEngine.ConfigurableJoint.linearLimit'. Consider storing the value in a temporary variable

    Does it have something to do with the fact that ConfigurableJoint.linearLimit derives from SoftJointLimit.limit?
     
  2. Brad-Newman

    Brad-Newman

    Joined:
    Feb 7, 2013
    Posts:
    184
    I solved it with the following code:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class SetLinearLimitDamper : MonoBehaviour {
    6.    
    7.     void Start () {
    8.         ConfigurableJoint configurableJointComp = GetComponent<ConfigurableJoint>();
    9.         SoftJointLimit softJointLimit = new SoftJointLimit();
    10.         softJointLimit.damper = 1f;
    11.         configurableJointComp.linearLimit = softJointLimit;
    12.     }
    13. }
    14.  
     
  3. esitoinatteso

    esitoinatteso

    Joined:
    Sep 23, 2013
    Posts:
    26
    Thanks a bunch!:D