Cannot select Animation Event

I’ve copied an animation in order to make it R/W, added the component script below to the GameObject, then created an Animation Event. However, I cannot select my function (MeshState) from the list. It does not appear on the list. The list is empty.
[28380-animation+event±+edit+animation+event±+no+function+selected.jpg|28380]

// MeshHider.cs
using UnityEngine;
using System.Collections;

public class MeshHider : MonoBehaviour {

	public Renderer meshSelection;
	public bool meshHidden;

	public void MeshState(bool meshHidden){

		if( meshHidden == true)
			{
			meshSelection.renderer.enabled = false;
			}
			else 
			{
			meshSelection.renderer.enabled = true;
			}
	}
}

I would like to add a tip/hint/possible solution to those who might find themselves in this kind of situation which is resolved quite easily when you know what’s happening.

The Event key in the Animation windows in Unity is used by TWO sub-system of Unity’s animator system at once. There are what I call a “direct” and an “indirect” sub-system.

Let’s explain what is both :

1. The Direct


It is Instance based and is only accessible if you select the animation’s gameobject through the Hierarchy window. This method requires that you place a script with the desired function on the animated gameobject itself. It’s a bit similar to the UI’s button component as in which you can have some controls over who’s targeted by the event as long as it’s done through the script’s function. This is the one displayed in the screenshot above.

2. The Indirect


This one is based on what scripts are currently awaken in the scene. You got to select the animation through the Project window. This is the kind of event menu displayed in the documentation. It’s using a radio-based call which mean that all listeners active in the scene that has that function will activate when it’s the event is called if it exist. (TR. It means that any scripts awakened (started) that has the function’s name in it will activate the function with the given parameters if available.)

The best kind of example I could give for the 2 are the following :

The direct is useful for specific event that are only happening to 1 gameobject at a time. For example, if you want each step of your character to generate some kind of dust or if you want a melee attack to only count at a specific frame, this is the kind of method you could use.

The Indirect is useful for scene-based events. For example, you could have something like a nuke explosion and have an even in it that send the call “AllDies” where all the NPCs on the map has a script including that kind of function. It could also be related to event that affect AIs such as a call that update the Pathfinder’s script of all the NPCs. (Such as if a gate is closed, no NPC try to cross it.)

One thing is required in BOTH way and that’s that the function does exist “at least” on any scripts in the actual animated gameobject. The Direct method require a specific script to be attached selected while the Indirect method allow you to use whatever script you want as long as the script is attached to the same Gameobject as the one with the animator. The indirect method is great if you plan on instantiating stuff on the fly (like adding scripts mid-game) like a customization system.

The answer was simple, after lots of head scratching. You cannot use boolean! The below works in case anyone else stumbles onto this:
using UnityEngine;
using System.Collections;

public class MeshHider : MonoBehaviour {
	public Renderer meshSelection;
	public int meshState;
	public void MeshState(int meshState){
		if( meshState == 1)
		{
			meshSelection.enabled = false;
		}
		else 
		{
			meshSelection.enabled = true;
		}
	}
	
}

Just now this happened to me. Then I remembered that I have attached the script with those functions for AnimationEvents to a prefab. After deleting a script from a prefab, this works again! :wink: (And adding a script to a prefab again, made the list of functions to become empty)