I have used the code posted here http://forum.unity3d.com/viewtopic.php?t=15644&highlight=animationevent It looks like the event is correctly triggered on animation clip end, but I get the error "<myFunctionName> has not receiver". Could somebody kindly help. Many thanks.
What this means that that your AnimationEvent is trying to call back with a function name that doesn't exist. You can supress this error by flagging the event like this; myEvent.messageOptions = SendMessageOptions.DontRequireReceiver; However it implies the function name you specified in your AnimationEvent is missing. Does this help? Charles
One more thing; When the event is handled a SendMessage is used to call the function name you specify, and this function must exist in the same level in you hierarchy (or possibly lower), not in a component in a parent object, as AnimationEvent does not use SendMessageUpwards. Charles
Thanks for the help. please kindly find the source code here: it looks like the <<don't send message>> option does not fit my requirements, so I need to understand why the event handler is not recognised by the animation event Code (csharp): var mySkin : GUISkin; var animatedGameObject : GameObject; var horOffset = Screen.width * 0.18; private var animationEvent : AnimationEvent; //Solved: move this function to a script attached to the animatedGameObject function AnimationEnded(animEvent : AnimationEvent){ animatedGameObject.animation.CrossFade ("idle"); } function Start(){ animationEvent = new AnimationEvent(); animationEvent.time = animatedGameObject.animation["attacco"].clip.length * 0.9; //animationEvent.messageOptions = SendMessageOptions.DontRequireReceiver; animationEvent.functionName = "AnimationEnded"; animatedGameObject.animation["animation1"].clip.AddEvent(animationEvent); animatedGameObject.animation["animation2"].clip.AddEvent(animationEvent); } function OnGUI () { GUI.skin = mySkin; if(GUI.Button (Rect (Screen.width * 0.0 + horOffset, Screen.height * 0.75,Screen.width * 0.18, Screen.height * 0.25),"")){ animatedGameObject.animation.CrossFade ("animation1"); } if(GUI.Button (Rect (Screen.width * 0.20 + horOffset, Screen.height * 0.75,Screen.width * 0.18, Screen.height * 0.25),"")){ animatedGameObject.animation.CrossFade ("animation2"); } }
I got it now. The function handling the animation event must reside in a script attached to the animated object. I had not understood your suggestion in the first go. Thanks again.
Hi, Im trying to make some animation events to work, first I try with this example: Code (CSharp): public SimpleEventReceiver _EventReceiver; public AnimancerState activeState; _EventReceiver.onEvent.Set(activeState, (animationEvent) => { Debug.Log("_EventReceiver"); }); The I put in the animation some event called "Event" with no params (or params, is the same for the case) And I get an error "NullReferenceException: Object reference not set to an instance of an object." because dont recognize the "animationEvent" param for some reason. I try to create directly a public void function called "Event", in the same controller, and in this case is executed, so im not sure what im doing wrong.