♪♪♪
Wes Bunn: Hello again everybody and welcome.
In this video, we are going to take a look at Blueprint communication
This includes several types of Blueprints, as well as the Level Blueprint.
Let's go ahead and get started.
I have the Blueprint First Person Template project open.
I also have Starter Content enabled, so we have some things to play with.
Right-click inside the Blueprints folder and select Blueprint Class.
In the Pick Parent Class menu, select Actor.
Name this this Blueprint the "Movable Cube".
We are going to place this Blueprint inside of our level and have our Player Character Blueprint
interact with it in a way so that we can move the cube
around our level whenever a button is pressed by our Player Character.
Double-click to open the MovableCube Blueprint.
When we open the Blueprint, it opens the Blueprint Editor to the Viewport tab
allowing us to see the components we add to our Blueprint.
Let's go ahead and add some Components. In the Components panel, click +Add Component
and select the Static Mesh Component because we need to add a Static Mesh.
UE4 prompts us to enter a name. Name this Blueprint "Cube".
Go to the Details panel. This is where all the properties can be set to affect this Static Mesh Component.
The only one we are really going to worry about is actually defining a Static Mesh,
Click the Static Mesh drop down, and type "Cube". Select Shape_Cube.
Actually, I am going to do one more. Let's see here.
Click Compile and click Save.
I am going to change the Material because it is just plain white (M_Basic_Wall).
Let's make it a little bit more fancy. Click the Material drop down, and type "gold".
Let's make it a golden cube. Select M_Metal_Gold. There we go.
Go to the Event Graph.
This is where we provide the scripted functionality for this Blueprint.
There are a few nodes here by default. We are not going to worry about any of those.
Right-click, hold down RMB
and drag those nodes off-screen because we are going to add our own.
Right-click again, release, type and select "Custom Event" in the search bar.
A Custom Event will allow us to name the event
as well as provide any kind of inputs
that we want to specify as variables for this event.
Click the Add Custom Event button.
UE4 is going to prompt us to enter a name. Name this Custom Event "MoveCubeEvent".
We could call this Custom Event inside this Blueprint.
Right-click, type and select "MoveCubeEvent". You can see we can call that function here.
We can also call this Custom Event externally from other Blueprints.
That is exactly what we want is to be able to communicate with this Blueprint.
First, we are going to make sure that our Custom Event is selected.
We're going to add an input here.
In the Details panel, click the New button.
UE4 adds the New Parameter input on the Custom Event. We are going to change the type.
Click the Input Type drop down and select Float.
We are going to give the input a new name. Name this input "Offset".
I will explain why momentarily.
The Custom Event is complete. Hold Ctrl on the keyboard.
In the My Blueprint panel, you can see our Cube Static Mesh that we added as a component.
Hold Ctrl + Left-click to drag Cube into the graph. This gets a reference to our component.
Left-click and drag off Cube.
Type and select "Add Local Offset".
Once I press Enter, the Local Offset will give us a new node.
Add Local Offset adds X, Y, and Z values for Delta Location to offset
our current X, Y, and Z location in our world.
This is going to be perfect for what we are trying to do.
Drag off Delta Location and release,
you can see there is an option to Make Vector down at the very bottom.
Make Vector makes an X, Y, and Z vector. Select Make Vector.
You see the Make Vector node is asking for float values.
We are not going to worry about the X and Y values. We are only going to worry about the Z values.
The Z value will push us up into the air.
Plug Offset into Z.
Now, the Offset is something we can specify externally.
The Offset will be provided to our Make Vector, and offset our current Z value for our Cube.
It makes a lot more sense once we get into the level and play.
Left-clicking + drag off MoveCubeEvent, and plug the wire into the Add Local Offset.
Click Compile and click Save.
Go back to the level now.
First, we need to drag-and-drop the MovableCube Blueprint into our level.
Once MovableCube is in the level, go up to the Toolbar. Click the Blueprints button in the Toolbar.
In the middle, there is a section called Open Level Blueprint.
The Level Blueprint is a unique Blueprint
that can only be accessed per level, as the name suggests. Click Open Level Blueprint.
We are going to affect this current level.
Let's do one thing really quickly.
I am going back to the level to make sure that our Cube is still selected, which it is.
Go back to the Level Blueprint.
Right-click in the graph
and you can see it says Create a Reference to MovableCube, which is stored in our level.
We can now call the functions inside our Level Blueprint
because we have a reference to it. Type and select "Move Cube Event".
Once selected, you can see UE4 creates two (2) new nodes:
the reference to our Actor in our level (MovableCube)
and our Custom Event (Move Cube Event) that was created inside of our Blueprint.
You can see it has the Offset and the same name.
Move Cube Event is asking for an Offset. Let's go ahead and put one in. Set Offset to 200.
Right-click in the graph again, type and select "F" for an F keyboard event.
Off the Pressed... These are the Pressed and Released inputs for the F key on your keyboard.
Connect Pressed to the Move Cube Event executable.
Click Compile.
Go back to the level and click Play.
Whenever we press F, this cube should move up 200 units each time.
When we press F, you can see it goes up 200 units.
The cube goes up 200 units every time we press F.
There we go. We are communicating from our Player Character Blueprint to the Level Blueprint,
and from the Level Blueprint to our Movable Cube Actor Blueprint.
There is one more thing we want to do. We want to have our Movable Cube Blueprint
interact with our Player Character Blueprint in some way.
For example if we shoot the cube, we want it to affect our Player Character in some way.
Now we don't have health or anything to display, so we are going to do something
kind of funky, but we will give it a try.
Go to the Movable Cube Blueprint.
First, we are going to create an Event Dispatcher.
Click the +Event Dispatcher button. UE4 asks you to enter a name for it.
Name this Event Dispatcher "MovePlayerEvent".
Drag the MovePlayerEvent into the graph.
UE4 gives us several different options. Select the Call MovePlayerEvent option.
Whenever MovePlayerEvent is called inside any other Blueprints
where we implement this Event Dispatcher, that script will also get called.
I will show you this here in a moment.
Right-click in the graph, type "Event Hit".
There we go. Select Collision Event Hit.
Connect the Event Hit executable to Call MovePlayerEvent.
What we are saying is whenever this Blueprint is hit, call our Event Dispatcher.
Click Compile and click Save.
Go back to the Level Blueprint. Your tab should still be open across the top here.
Go back to our Level Blueprint.
Right-click and let's search for "Move Player Event".
There it is. Add Move Player Event from our Movable Cube Blueprint.
There we go. This is our Event Dispatcher that will get called whenever the Cube is hit.
Right-click in the graph, type and select "Get Player Character".
We are going to get the Player Character.
Now, we are going to use a Cast node.
A Cast node is a way to verify if something is something else.
Drag off the Return Value, and type "Cast To".
There are a few options here.
We want our PlayerCharacter Blueprint, so select FirstPersonCharacter Blueprint.
Connect MovePlayerEvent to Cast To FirstPersonCharacter.
Then once we have our FirstPersonCharacter Blueprint, we want to do something with it.
Drag off As First Person Character, type and select "Launch Character" because that is fun.
There we go. Let's actually do one last thing on the Z.
Just like the Z value moved up our Cube, let's increase Z
up and launch the Player Character along the Z-Axis as well.
Set Z to 2000 just to make sure it works,
and launches our Character up pretty high.
Click Compile. Let's go back to the level and Play.
When we press F, it moves our cube up into the air.
When we shoot it, our character launches into the air. Boom!
Boom! Yeah, keep launching me up!
There we go. Yeah!
There you go. We are interacting with our Cube from our Player Character.
Our Cube is interacting with our Player Character when it is hit,
so we are getting some back and forth interaction.
This could be a game on its own right there.
How high can you get? How high can you get? Oh! No!
I saw that going much better, but you get the idea.
There you go. We are communicating between our Cube and our Player Character,
and from our Cube back to our Player Character.
I hope you all enjoyed this video and we will see you next time.
♪♪♪