0
Answered

How to Trigger an Action with Animation Event

Crispy 1 year ago in Game Creator updated by Marti (Lead Developer) 1 year ago 8

So far ΛRTΣMΛ has helped me get this working, but the problem is it activates all Triggers that have On Invoke. I've done the following, but I'm looking for a way to choose the triggers that an Animation Event activates:


Added animation to controller


Added Animation Event which calls the function ExecuteTrigger()

(What is the Game Object field for?)

Basic Trigger to play Animation


This is the Trigger that receives the Animation Event. Must put this on the child of Character or Player that has the animator controller in which you added your animation in the first screenshot.

In Discord, you said I should call the function ExecuteWithTarget(), and I believe this is the solution, however, how do I set the Target. The Game Object seems to only take in prefabs, ranging from models to effects to Behavior Actions:

Unity version:
2018.4.5f1
Game Creator version:
0.9.9

Answer

Answer
Answered

I would highly discourage you from modifying the Animator that comes with Game Creator. Otherwise, when you update to a newer version, you'll lose all your changes.

Instead, try using the Gesture & States system. It's much easier to use. To play an animation, simply call the Character Gesture Action and it will automatically play the selected animation on the desired character. Animation events should work fine using Gestures.

Answer
Answered

I would highly discourage you from modifying the Animator that comes with Game Creator. Otherwise, when you update to a newer version, you'll lose all your changes.

Instead, try using the Gesture & States system. It's much easier to use. To play an animation, simply call the Character Gesture Action and it will automatically play the selected animation on the desired character. Animation events should work fine using Gestures.

What I want to do is call an Action at a specific point during a Gesture. How do I do that?

Under review

Sorry I read the question too fast. I believe you should add an Actions component where the Animator is. If it's the Player, the first child of the character is where you need to add the Actions.

As for the Game Object parameter when calling the ExecuteWithTarget function, it's a reference to the game object that will be used when in an Action you select Invoker. If you don't use the Invoker option anywhere in this Action, you can leave it empty.

Yes, I did the first part as you can see in the screenshot under where I said: "This is the Trigger that receives the Animation Event. Must put this on the child of Character or Player that has the animator controller in which you added your animation in the first screenshot.


For the ExecuteWithTarget function, what exactly do I put inside the Game Object parameter, because it only takes in prefabs?

It does not take in the "game object that will be used when in an Action you select Invoker". For example, I can't drag in the following object. I'll make my question really simple: Is there any other Trigger I can use to receive an Animation Event other than using On Invoke?

The Trigger is needed there. Unity's Animation Event sends a message (tries to call a method from all components with a specific name) directly to the Actions. If this doesn't work, you can always create a small script that executes an Action such as this one:

using GameCreator.Core;

public Actions actions;

public void ExecuteEventCallback()
{
    this.actions.Execute(gameObject);
}

Drag and drop this component onto the object that has the animator and as the event name, type in "ExecuteEventCallback", without any parameters. Then, drag and drop the Actions object you want to execute onto the actions field in this component. Hope this helps!

+1

Well, On Invoke works. And it seems that script does the same thing. So I got my answer. Thanks.

Answered

Excellent! Cheers!