Search Unity

Animation Event problem

Discussion in 'Scripting' started by Lokken, Mar 4, 2012.

  1. Lokken

    Lokken

    Joined:
    Apr 23, 2009
    Posts:
    436
    Hi all

    My scene has 44 instances of the same FBX model. There is no prefab connection to the FBX model, the gameobjects were simply duplicated in the scene view.

    There is a script on them all that adds an animation event to one of the animations in the Start Function.

    Other scripts determine _ONE_ of these 44 to play that specific animation. All 43 others continue to play their 'idle' animation.

    The event gets called 44 times, once for every existing gameobject even though only one of them plays the animation with the event on it.

    Why is this?

    The script as it exists on all of the GameObjects is below:

    Code (csharp):
    1.     void Start () {
    2.         attached = new AnimationEvent();
    3.         attached.time = .6f;
    4.         attached.functionName = "startAttaching";
    5.         animation["Attach Direct"].clip.AddEvent(attached);
    6.     }
    7.  
     
  2. eekllc

    eekllc

    Joined:
    Dec 14, 2009
    Posts:
    19
    Yes... the same thing is happening here. It seems as if all GameObjects use one instance of the clips, but that doesn't work when you want to know when a particular object is triggering an animationevent.