Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Animations event doesn't accept any function to call

Discussion in 'Animation' started by Pierre-Marie, Jan 4, 2023.

  1. Pierre-Marie

    Pierre-Marie

    Joined:
    Aug 3, 2015
    Posts:
    51
    Hi I'm trying to get a particul effect trigger by a animation event.
    I made a script with a function to play the particule effect.

    I would like to call that function at a point of my animation.
    So I added a event at the right moment, but then can't use the event to do anything
    upload_2023-1-4_16-40-38.png

    How Am I suppose to fill this ? Object no gameObject.
    Really frustating as in the tutorial you have a dropdown list with function you can call and I have this things..

    Thanks for your help.
     
  2. JustinNaicker

    JustinNaicker

    Joined:
    Jan 4, 2023
    Posts:
    47
    Can you share the script?
     
  3. JustinNaicker

    JustinNaicker

    Joined:
    Jan 4, 2023
    Posts:
    47
    Your GameObject should be public.

    Your Event should be calling a public method within the script.
     
  4. steven708

    steven708

    Joined:
    Jan 4, 2023
    Posts:
    1
    When you hover your cursor over a marker, a tooltip displaying the function name and argument value appears. By hovering the mouse over an Animation Event marker, you can see the function it calls as well as the argument value.
     
  5. JustinNaicker

    JustinNaicker

    Joined:
    Jan 4, 2023
    Posts:
    47
    I believe he is in the Animation Event Window; His issue is that he is unable to put anything into his Object field.
     
  6. JustinNaicker

    JustinNaicker

    Joined:
    Jan 4, 2023
    Posts:
    47
    Also you mentioned your script contains the field Object gameObject. It should be GameObject gameObject, which is why I believe it is not working. The field you put is looking for an Object, while the particle effect you are trying to instantiate is a GameObject.
     
  7. Pierre-Marie

    Pierre-Marie

    Joined:
    Aug 3, 2015
    Posts:
    51
    Hello, thanks for your respond. Today After restarting unity it's fixed.
    Unity event look like that :
    upload_2023-1-9_9-52-38.png

    this is my script for info :

    Code (CSharp):
    1. public class StartAnimationScript : MonoBehaviour
    2. {
    3.     [SerializeField] private ParticleSystem ps;
    4.     // Start is called before the first frame update
    5.     public void StartParticuleSystem()
    6.     {
    7.         try
    8.         {  
    9.             ps.Play();
    10.         }
    11.         catch
    12.         {
    13.            
    14.         }
    15.     }
    16. }
    Now I have to work on the effect to match the movment of the animation.
    Any tips about that? When I play this animation in this animator, the event and particule are not display. I have to play it in the scene to see the particule effect.

    Thanks for your help.
     
  8. JustinNaicker

    JustinNaicker

    Joined:
    Jan 4, 2023
    Posts:
    47
    I would store the position of where you want the particle to leave from, and then instantiate the particle at that position in a method. Then you can call the method on the AnimationEvent. Then after a certain time, destroy the particle.
     
  9. JustinNaicker

    JustinNaicker

    Joined:
    Jan 4, 2023
    Posts:
    47
    Also, may you clarify for me, it plays in the scene view. Does it work in the game view and the ParticleSystem animator?