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

How do I access this weight value?

Discussion in 'Animation Rigging' started by Amuwaru, Feb 22, 2020.

  1. Amuwaru

    Amuwaru

    Joined:
    Dec 17, 2019
    Posts:
    16
    Hey y'all,

    I'm trying to access this value from the TwoBoneIKConstraint script:

    https://docs.unity3d.com/Packages/c...e_Animations_Rigging_RigConstraint_3_m_Weight

    And I'm getting the component like this:

    gameObject.GetComponent<TwoBoneIKConstraint>();


    That's not working because it says that the type doesn't exist and I'm probably doing it the wrong way -- so how do I go about accessing this component?

    Also I wonder if I can change it at runtime? I don't want to animate the value with the animator or do it via the Inspector.
     
    Last edited: Mar 4, 2021
  2. danUnity

    danUnity

    Joined:
    Apr 28, 2015
    Posts:
    229
    Hi,

    Yes its definitely possible to change the weight at runtime.

    Code (CSharp):
    1. TwoBoneIKConstraint constraint = gameobject.GetComponent<TwoBoneIKConstraint>();
    2. constraint.data.targetPositionWeight = 0.7
    3.  
    You can control other parameters too but you can't change the sources or targets at runtime for example since they are part of the animation graph built once when you start the game.
     
  3. Amuwaru

    Amuwaru

    Joined:
    Dec 17, 2019
    Posts:
    16
    For some reason the TwoBoneIKConstraint type just doesn't exist for me to be able to reference it like that (see original post).
    Am I missing something here?
     
    kaancetinkayasf likes this.
  4. zaclegarssure

    zaclegarssure

    Joined:
    Jan 24, 2019
    Posts:
    2
    Hi, it should work, maybe you forgot a using directive ?
     
  5. Amuwaru

    Amuwaru

    Joined:
    Dec 17, 2019
    Posts:
    16
    Which directive should I include in my script?
    I tried adding UnityEngine.Animations.Rigging or something like that and also the UnityEngine.Experimental.Animations but neither of them have that class defined.
     
  6. zaclegarssure

    zaclegarssure

    Joined:
    Jan 24, 2019
    Posts:
    2
    UnityEngine.Animations.Rigging should be the right one, so it doesn't seem to be the problem here.
     
  7. Amuwaru

    Amuwaru

    Joined:
    Dec 17, 2019
    Posts:
    16
    Soooooo...
    What do I do?
     
  8. SpiccyMayonnaise

    SpiccyMayonnaise

    Joined:
    May 10, 2018
    Posts:
    22
    You need to be using the namespace "UnityEngine.Animations.Rigging".
    Just put this line at the top of your file:

    using UnityEngine.Animations.Rigging

    If this doesn't work, let me know. It might be because you are on a different version of Unity. Also, make sure that you are updated to the latest version of the Animation Rigging package, you can update through the Package Manager.
     
  9. Amuwaru

    Amuwaru

    Joined:
    Dec 17, 2019
    Posts:
    16
    As I've mentioned before, I did use that namespace and the other from Experimental, but neither didn't have the class defined.
    I was using Unity 2019.3 and the Animation Rigging package was up to date (when I first posted this)

    I decided to go for a different approach since this doesn't work, so thanks anyway...
     
  10. Levr01

    Levr01

    Joined:
    Jun 6, 2017
    Posts:
    26
    Nice same problem - using UnityEngine.Animations.Rigging, and get "UnityEngine.Animations.Rigging" not exists ! Great !)
     
  11. Levr01

    Levr01

    Joined:
    Jun 6, 2017
    Posts:
    26
    Im find a way - this is a reference bug. need refresh a reference library in project
     
    kaancetinkayasf likes this.