Animation-Event Message
m |
(Removed duplicated information) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | + | Animation events are used to initiate some action, such as smoke effects, during an animation cycle that can be detected by script. This is a different mechanism from Sound_Event, which interfaces with a [["Soundscript" container]] in config.txt and does not require scripting. | |
+ | When an animation event occurs, the game engine will post a message in the form: | ||
+ | "<major>, <minor>" | ||
+ | where the major part of the message is always "Animation-Event" and the minor part is a message of your choice. | ||
− | + | The structure and format of event files can be found here: [[FBX file format]] | |
− | + | To use the posted message you should define a handler using: | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
AddHandler(me,"Animation-Event","","AnimationHandler"); | AddHandler(me,"Animation-Event","","AnimationHandler"); | ||
Line 15: | Line 12: | ||
void AnimationHandler(Message msg) { | void AnimationHandler(Message msg) { | ||
if (msg.minor == "animstart") | if (msg.minor == "animstart") | ||
− | + | Interface.Print("Animation has started"); //action for the animstart event | |
+ | else if (msg.minor == "do-something") | ||
+ | Interface.Print("Do something here"); //action for the do-something event | ||
else if (msg.minor == "animstop") | else if (msg.minor == "animstop") | ||
− | + | Interface.Print("Animation has completed"); //action for the animstop event | |
} | } | ||
− | + | In practice the game engine often issues duplicate messages so you will need to ensure that you are not responding more often than necessary. One way of doing this is to use a boolean variable to keep track of what your script is doing and use this to ignore duplicating script actions. | |
==See Also== | ==See Also== | ||
+ | * [[FBX file format]] | ||
* [[List of Standard Messages]] | * [[List of Standard Messages]] |
Latest revision as of 16:18, 3 July 2020
Animation events are used to initiate some action, such as smoke effects, during an animation cycle that can be detected by script. This is a different mechanism from Sound_Event, which interfaces with a "Soundscript" container in config.txt and does not require scripting. When an animation event occurs, the game engine will post a message in the form: "<major>, <minor>" where the major part of the message is always "Animation-Event" and the minor part is a message of your choice.
The structure and format of event files can be found here: FBX file format
To use the posted message you should define a handler using:
AddHandler(me,"Animation-Event","","AnimationHandler");
void AnimationHandler(Message msg) { if (msg.minor == "animstart") Interface.Print("Animation has started"); //action for the animstart event else if (msg.minor == "do-something") Interface.Print("Do something here"); //action for the do-something event else if (msg.minor == "animstop") Interface.Print("Animation has completed"); //action for the animstop event }
In practice the game engine often issues duplicate messages so you will need to ensure that you are not responding more often than necessary. One way of doing this is to use a boolean variable to keep track of what your script is doing and use this to ignore duplicating script actions.