5. Eventos, Functions and Macros Events - Custom Events
The time has come to talk a little bit about Custom Events.
I'm going to delete what we had done before.
And here's the thing.
We said that these events here were already created by Epic.
But, we can create our own Events and call when we want.
To create a new Custom Event, I right click on the Grid.
I can type Custom. And it already appears to me.
Add Event. Custom Event.
Something I didn't show you in the previous classes...
If you right click it's in the Add Event category...
You have some options, right? The ones we've seen.
Tick and Beginplay.
There are several others. Mouse Input.
Used to call mouse Events.
Right? Collisions.
Actor events. And that's it.
You can access all here.
But, we want to create our own, So I'm going to type Custom Event.
It show to me Custom Event.
When I click, it will appear this...
This Node. We have the appearance that we already know.
It's asking for a name.
I'll type Custom Event 1.
So we can have a name here.
As I commented, everything we do, with an Event, is in the event Graph itself.
So if I double-click it, nothing happens, right?
There's nothing inside it.
Everything that's going to happen is going to be from itre. In the order of execution, from this Node here.
Ok?
So I'm going to do a basic operation.
Set. Value of the variable.
So, value 2.
A variable value 2, I'm going to Set 30.
So, what happens now? I have this Custom Event 1.
I can call it when I want.
The variable will have the value 30 here.
That way here, nothing happens, okay?
I need to call this event at some moment.
So I can, for example, call it on Beginplay.
And we have another option here.
That's Call Event.
When I type Call...
It's got the Call Function, right? It's a function...
And the only event I've created will appear. That's the Custom Event 1.
When I click, notice that from there the appearance is already different.
It is not the Event Node.
It's the function Node, okay?
It is a function that is calling that Custom Event.
So if I click on the Event BeginPlay, and add it here...
In the Order of Execution.
Then, when the Event Beginplay starts, It will trigger the Custom Event 1.
Which is exactly what's here.
So I can have, for example... This Custom Event elsewhere.
Right?
On my Graph.
And add several changes here.
Just so we can have more things.
And all the logic of Custom Event 1 is happening here.
I can keep it reserved, in an area.
And when I need to call this event itre, I call when I want to, right?
In this case here, I'm calling it on Beginplay.
I could call that Custom Event with...
some input from the keypad, huh? Or using input from the mouse, for example.
Another thing we will see in the future...
That's going to make a little more sense.
It's the communication between BluePrints. So, I can have an event here, on this BluePrint...
That's going to be executed by another BluePrint, okay?
We have to talk here, for sure, about the difference which we saw between functions and events.
Here the events are based on time, So I can add in my events...
some time Nodes, right? So we talked about the Delay Node.
We hadn't seen this Node before.
I type Delay in my Flow Control.
Delay.
As soon as I select it, it appears the Delay Node. And it's a very simple Node.
You do realize you have a little watch there, don't you? It's a time Node.
And it has the duration here, which is a Float number.
In this case, it's 0.2 now, in seconds, okay?
I can leave, for example, 5 seconds.
Right?
So, I'm going to delete everything, these guys here.
And I'll connect the Delay to my Custom Event.
Right?
And then I'm going to use a Print String. Then, just so we can see something on the screen.
It could be Hello himself.
So, what is this Custom Event doing?
As soon as the Custom Event is called, It's going to have a 5-second Delay.
So you're going to be waiting itre for five seconds.
After 5 seconds, It will continue execution.
Ok?
So let's call it. Let's call it when the game starts.
It's already happening, right?
It calls the Custom Event. So, now, let's compile.
Remembering that we're in an Actor, right? So the Actor has to be in the scene.
BP_Eventos-Funcoes. It's this BluePrint that I'm using.
So I drag it on the stage, so that happens.
And now, when I Play...
Nothing happens. We'll count for five seconds.
And Hello appears.
So, what happened, actually?
So when the Event Beginplay was called, right? When the game started...
It called the Custom Event 1.
And then I double-click this Custom Event, to go to this Event.
So it brings me here. The Custom Event is here.
What does it do? It gives a 5-second Delay.
So...
It waits on this Node for 5 seconds and then it continues execution.
Send us a Hello.
So that's what happens.
Good to know the difference between events.
You create the event and then you make a Call.
Right?
It's a Call Function, actually. is a function that is calling the Custom Event.
So, for you to call the Custom Event, You have to add this Call function, ok?
The Custom Event 1. I only have one, right?
It's here, defined in this portion here.
I can't, for example...
CTRL + C + CTRL + V.
It gives an error.
I can't have one more Custom Event 1, ok? There's only one in this BluePrint.
But, the Call Function, I can have many. So it means I I can call that Custom Event as many times as I want.
Ok?
So, in case I want to create one more Custom event, we go on ADD custom event...
It's going to give me a name.
Custom Event 2.
And then it can execute whatever I want. In this case, I can call the Print String.
It's going to execute that for me.
Hello, in Portuguese.
Then I can call it at Beginplay as well.
So...
When the game starts, call the Custom Event 2.
So it's going to call the Custom Event 1 And will not wait, will call the event 2 right away.
Let's see what happens.
There's Ola, see? First.
Then that Custom Event 1 was called.
It plays 5 seconds and appears Hello.
So even if the order here is first the Custom Event 1 and then the 2...
We have to remember that Events are time-based.
So it called the Custom Event 1 first.
So it called this one here. This guy's been called.
Except it's got a Delay. So, that's why Hello didn't show up.
And the Custom Event was called right after that. Almost immediately.
Then Ola appeared, Because there wasn't a Delay there.
So, here, after five seconds, it will appear the Hello.
So remember the Nodes of time, ok?
I have Delay here. We will see the Node called Timeline in another class.