Hey there!
I read somewhere that it's odd to have multiple components of the same kind (and of the same name) on one game object so with the Play Maker FSM (Script)s, it's a unique situation. The way to specify is to create an array of the components and reference them using the integer of the component you need. In my situation, I won't know the intager of the component will be the same on each game object so I make the array and send the event to all FSM components.
It's working in a way I'm okay with so I'll leave this here in case someone needs a similar script:
using UnityEngine;
using HutongGames.PlayMaker;
public class AnimationEventsToFSM : MonoBehaviour
{
private PlayMakerFSM fsmArray;
public void Animation_Event(string stringToInput)
{
// Finds all PlayMakerFSMs on the GameObject
PlayMakerFSM[] fsmArray = GetComponents<PlayMakerFSM>();
for (int i = 0; i < fsmArray.Length; i++)
{
// Sends events to all FSMs
fsmArray[i].SendEvent(stringToInput);
}
}
}
This script is meant to work with the
un-editable animation clips normally nested inside the fbx.
- Put this script on a Game Object with (1.) the Play Maker FSM (Script) component(s) you wish to send animation events to and (2.) the Animator Controller playing the un-editable animation clips you wish to send events from.
- Use the inspector to find the animation clips you want to put events on and add the event keys to the timeline there.
- Edit the Function of each key to say Animation_Event (or edit the function in the script to use what ever you want) then add the exact name of the FSM events you wish to send to the String field.
Like this:
- When the animator of that object plays the animation clip, it will send the events to all FSMs on the object at the keyed time, triggering the correlating event inside the FSM.
I hope this helps someone in a similar situation as myself! Also if anyone sees something wrong with the code, please let me know because I'm just stumbling around in the dark when it comes to this stuff.
Thanks!