♪♪♪
Wes Bunn: Greetings and welcome everyone.
In this video, we are going to take a look at how we can publicly expose variables inside our Blueprints
upon spawning them in our level.
Let's get started. We are using the Blueprint First Person Template project with Starter Content enabled.
First, we are going to create a brand new Blueprint. Go to the Basic tab of the Modes panel.
Left-click + drag an Empty Actor into our scene.
Let's add some Components to the Blueprint in the Details panel.
Click the Add Component button.
Type and select, "Scene Component" . This will allow us to manipulate the transform of this Blueprint .
Name this Scene Component "Root". Click +Add Component, type and select, "Static Mesh Component".
The default name is fine.
In the Details panel under Static Mesh, click the drop down, type and select "Shape_Sphere".
With that, let's turn this Component into a Blueprint so that we can add some script to it.
Click the Blueprint/Add Script button. Name this Blueprint "Sphere_Blueprint".
Click Create Blueprint.
UE4 is going to create a brand new Blueprint in the Content Browser and open a new tab for us.
Click the Sphere_Blueprint tab. We are now inside the Blueprint Editor Viewport tab.
First, we are going to create a new variable that we can publicly expose on spawn.
In the My Blueprint panel, click +Variable.
For this example, name this variable "Velocity".
In a moment, you will see why.
In the Details panel, click the Variable Type drop down and select Vector.
Check the Editable checkbox to make the variable publicly editable,
Check the Expose on Spawn checkbox as well.
Click Compile. Go to the Construction Script.
On the Construction Script, hold Ctrl + drag in our StaticMesh.
Actually, there is one more thing we need to do before I forget.
Select the StaticMesh, and check the Simulate Physics checkbox in the Details panel. Physics are fun.
Now that physics have been enabled, drag off Static Mesh,
and type "physics". There are several options in here.
Scroll down and select "Set Physics Linear Velocity".
Connect the Construction Script to Set Physics Linear Velocity.
Select the Velocity variable. The Set Physics Linear Velocity node is asking for a vector.
Drag-and-drop Velocity onto the New Vel pin.
There we go. Our Blueprint is set. Click Compile and Save.
Go back to the level.
We can delete this instance of Sphere_Blueprint in the level. Select it and press Delete.
In the Modes panel, type and select "Target Point".
because we are going to use this as a spawn location.
Left-click + drag in Target Point.
I am going to drag it up into the world because that is going to be cool.
Go to the Level Blueprint.
At the very top, click the Blueprints button and click Open Level Blueprint.
Make sure you have Target Point is still selected, which we do.
Go back to our Level Blueprint. Right-click, type and select "Create a Reference to Target Point".
Right-click and press "F" for the F key.
We did this so that we can get a reference of where we want to spawn
our Sphere_Blueprint whenever we press F.
The first thing we need to do is actually spawn it. Right-click, type and select "Spawn Actor from Class".
Connect Pressed to Spawn Actor from Class.
You see it is asking for a transform, so let's
provide that. Drag off Target Point, type and select "Get Actor Transform".
Plug the Return Value into Spawn Transform.
Click the Select Class drop down menu and select Sphere_Blueprint. Watch what happens to the node.
Sphere_Blueprint.
Now we can specify a Velocity at which to spawn our Blueprint.
For fun, let's Right-click, type and select "Random Unit Vector". That is the one we want.
Drag off the Return Value, type "*" and select Vector * Float. This will allow for a large spawn radius.
Set B of the Multiply node to 500. You can set it to whatever you would like.
Let's plug that in to our Velocity like so.
Click Compile and go back to the level.
Now when we click Play and press F,
you can see the sphere is being launched at a velocity
that we specified to occur on spawn.
There you go, you have learned how to expose a variable
that can be edited on spawn. You can use this in a number of different ways.
We could change the Material on Spawn. We could change
the actual Static Mesh on Spawn if we wanted.
It is completely up to you and your gameplay needs.
I hope you all enjoyed this video and we will see you next time.
♪♪♪