Search Unity

SetCurve and boolean operations

Discussion in 'Animation' started by KB73, Apr 4, 2014.

  1. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    I'm running into some difficulty changing boolean properties with SetCurve.

    I have it working on my own custom scripts fine but it appears to be problematic on the Unity Components themselves.

    AnimationCurve c = new AnimationCurve()

    Keyframe1 = new Keyframe(0.0F,0.0F);
    Keyframe keyframe2 = new Keyframe(10.0F,0.0F);

    c.AddKey(keyframe1);
    c.AddKey(keyframe2);

    animClip.SetCurve("",typeof(BoxCollider),"isTrigger", c );

    Nothing changes.

    If i use my own component with the above code and my own bool var, the bool changes fine.

    if i add BoxCollider isTrigger to an animation window via the animation window menu and change the flag it works fine.

    If open up the animation window once i have run the code above, i see my variable but the text is flagged as red and there is no checkbox next to the variable name. This is the one difference i can see versus adding the curve directly in the animation window.

    Rotations,Positions and everything else work fine.

    Is there something else i have missed? I thought maybe the tangent mode not being stepped would be an issue but even changing that in the animation window on my curve has no effect.

    This pretty much applies to any bool in any of the normal components, enabled, isTrigger etc in Animation,Transform, MeshRenderer etc

    I tried changing the animation type in debug from legacy to generic etc to no avail.

    I'm on Unity 4.3.4f1

    Any ideas?

    cheers
     
  2. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    Having done some tests, it looks like it's because it is something to do with accessing properties directly or via an accessor ( get{} set{} ). If you do it directly it works, if you do it via an accessor, it fails. I'll confirm this later after checking a bit further.
     
  3. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    Ok so it is not directly due to the accessor

    If i take my custom script, make an accessor, make my interval bool var private it fails
    if i do the same but make the internal var public, it works
    If i add the SerializeField tag on the private version, it works.

    So, i think it's just a bug with Unity, will log it.
     
  4. mjmjmtl

    mjmjmtl

    Joined:
    Mar 6, 2014
    Posts:
    2
    Hi KB73,
    I also met with this problem, and I found a solution to solve it:
    1.without any script, build a animation, which include the BoxCollider and IsTrigger value curve.
    2.using text editor to open the ".anim" file, then search "trigger". You'll found that the real name is "m_IsTrigger" !!!!!
    3.use "m_IsTrigger" as the propertyName when calling setCurve. Everything will work.
     
  5. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    Nice find, yep i spoke with the guys at Unity, basically all those property are as you showed, naming convention of m_ and capital first letter.
    I was just trying to use reflection for everything and i kept getting back just isTrigger ( which i assume is an accessor ) and the underlyings were hidden...

    All good.

    thanks

     
  6. mjmjmtl

    mjmjmtl

    Joined:
    Mar 6, 2014
    Posts:
    2
    Yes, I'm also quite interested in reflection in Unity. I tried several times but I'm only able to reflect the public fields. I'm not sure is it because Unity do something to hide their private fields, so we cannot reflect them.
    If you have new findings about it, you may told me. :)
    Thanks so much!