How to make a GameObject Prefab appear…as Animation Event, on an animation frame of character

Hi there! I am trying to get a gameobject prefab to ‘appear’ (be triggered) at a specific frame of an animation of a character. I learned that it is ‘Animation Event’ (on the animation itself) you must use to make ‘animation events’; so I opened the animation (in Animation window), clicked ‘add event’ at the desire frame, and then in ‘game object slot’, I added the desired prefab; but nothing happens, the prefab does not appear in the game at the frame - when the character plays this animation, no gameobject/prefab appears.

Now, I understand there must be some ‘signal’ to ‘get the prefab’ at that specific frame of the animation. I read that GameObject.SetActive…could be one… tried it does not work.
Invoke method, SetActive …or GetObject…the empty box fields say Int, Float, String…I’m not sure what is suppose to be the ‘right’ call to get the prefab at that frame (is it a string, bool…you must type there)…as a Animation Event.
Any help is greatly appreciated and thank you very much in advance.

PS: If you know, what would be the inverse…to make a gameobject prefab… disappear/turn off - at that frame.

I played with animation event once, and if I remember correctly the function has to be within the same object the animation is in. And also has to be your own public function, not a Unity method. So make a public function:

public void HandleMyAnimEvent01()
    {
        gameObject.SetActive(false);

        // or

        GetComponent<Renderer>().enabled = false;
    }

But as far as the difference between disabling a gameObject, versus just turning off it’s renderer, is purely up to you on how you want the situation handled. Does it need to no longer exist, or just be invisible? Use the correct method for the correct case.

Also is recommended to have the renderer cached in the class associated, so you wouldn’t need to get the component, just call it:
myRenderer.enabled = false;

But make your own function, and use the anim event to call that, and see if it works. :slight_smile:

1 Like

AnimationEvents:

1 Like