Search Unity

wrapMode not getting set...

Discussion in 'Editor & General Support' started by sl4ppy, Apr 13, 2010.

  1. sl4ppy

    sl4ppy

    Joined:
    Mar 23, 2010
    Posts:
    12
    (moved from scripting forum)

    I'm getting some very odd results when trying to set the wrapMode of an animation.

    Code (csharp):
    1.  
    2. UnitAI.gameObject.animation.wrapMode = WrapMode.Once;
    3. UnitAI.gameObject.animation.Play("death_01");
    4. Debug.Log(UnitAI.gameObject.animation.wrapMode);
    5.  
    When my code executes, the debug log line reports that wrapMode is set to clamp regardless of what mode I set the animation to just prior to playing the animation and the animation plays back in a loop in-game.

    My source animation asset is also set to Once in it's wrapMode in the inspector.

    Can anyone help me understand what's going on?
     
  2. sl4ppy

    sl4ppy

    Joined:
    Mar 23, 2010
    Posts:
    12
    To simplify a bit, why does this:

    Code (csharp):
    1.  
    2. gameObject.animation.wrapMode = WrapMode.Once;
    3. gameObject.animation["death_01"].wrapMode = WrapMode.Once;
    4.  
    5. Debug.Log( gameObject.animation.wrapMode);
    6. Debug.Log( gameObject.animation["death_01"].wrapMode);
    7.  
    always output

    Code (csharp):
    1.  
    2. Clamp
    3. UnityEngine.Debug:Log(Object)
    4.  
    5. Clamp
    6. UnityEngine.Debug:Log(Object)
    7.  

    I am totally baffled. It seems to defy logic. :/
     
  3. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Are you calling this code once (from the Start function, say) or from a regular update?
     
  4. sl4ppy

    sl4ppy

    Joined:
    Mar 23, 2010
    Posts:
    12
    in an update loop, but under a conditional...

    Further experimenting resulted in 'clampForever' behaving as I would expect, but 'once' behaving oddly.