506 Game Development and Simulation with Unreal Technology
16. Lastly, we can hide the visibility of the character mesh, as it is not relevant to our
game anymore. To do this, perform the f ollowing tasks:
a. Go to the Components tab of the MyCharacter blueprint.
b. Select Mesh1P in the components list.
c. Scroll down to the Rendering section of the Details window.
d. Check H idden in Game to temporarily hide the mesh.
17. When you compile and save, the arms will be visible in the editor but when the
game is play ed, they will be hidden.
What Happened in TUTORIAL 8.1. . .
At this point, we have completed our initial set up of the main project we will be
working on throu ghout th is chapter. We set up the level so that we have plenty of
room to add our own blueprints into the level.
The MyCharacter blueprint is now set up to function as a first person con-
troller, without th e weapon asset. We removed it because we d o not need the
weapon in the game we are making but if you would like to add it back in, it
should no t affect the game . I n the next tutorial, we will continue on to cre ate our
ball spawner.
FIND ON THE WEBSITE
To find updates to this tutorial and upda te d instructions about its implementa-
tion on othe r UE4 versions, p le ase visit the books companion Website at:
http://www.RVRLAB.com/UE4Book/
TUTORIAL 8.2 Spawning Actors with Blueprints
Now with our character and level set up, we need to create the bluep rints that
we will be working on.
CREATING TH E BALL AND BALLSPAWNER BLUEPRINTS
1. Navigate to the Blueprints folder in the Content Browser.
2. Create a new Actor blueprint.
3. Give it the nam e Ball and leave it alone for now. We will create our object using
this particular class blueprint later.
4. Next, create anothe r Actor blueprint.
5. Give the second blueprint the name BallSpawner.
6. Double-click on the BallSpawner b lueprint to open it.
Advanced Blueprint Concepts 507
ADDING COMPONENTS TO BALLSPAWNER
The purpose of th e BallSpawner is to be able to spawn our Ball blueprint
at the location of the spawner itself. When we have this blu eprint placed in-
game, the user will not be able to see it ( unless we have it visible for debugging
purposes). This will le t us have the illusion of spawning at random locations on
the board, w hen in reality it is goin g to be tightly controlled.
For level design and debugging purp oses only, we will p la ce a me sh in the
components section, so that we can see where our spawners are in the level.
7. Go to the Components tab of the BallSpawner blueprint.
8. Left-click on the A dd Component, and place a Capsule in the blueprint. Th is
will be our visual r epresentation of the spawners so that we can easily move them
around and know where they are located.
9. Rename the capsu le to Spawne r.
10. Locate the Deta ils window and scroll down to the Rendering sectio n.
11. Uncheck Hidden in Game so that it will be visible f or the time being.
12. Once this is done, you can compile and save.
13. Your blueprint components tab should look similar to Figure 8.5.
FIGURE 8.5: Adding Components to the Ball Spawner Blueprint.
ADDING FUNCTIONALITY TO THE BALL SPAWNER
14. Move to the even t g raph of our Ba llSpawner blueprint so that we can add the
functionality we need. To do this, Left-cl ick on the Gra ph tab o n the upper
right corner of the blueprint editor. The script in this par ticular blueprint will need
to handle the spawning o f the ball as well as telling the ball when to be destroyed
508 Game Development and Simulation with Unreal Technology
and informin g other blueprints that this ha s happened. We will b e building up to
this so that we can learn what e ach piece of the puzzle is doing as we go.
15. We need to create a custom event that will fire when it is called upon by either the
level blue print or another class blueprint. To create a custom event, perform the
following tasks:
a. Right-click on the event graph.
b. Type Add Cu stom Event in th e search box .
c. Place a Cust om Event in the graph.
d. Once placed, give the Custom Event the name Spawn Ball.
16. To place an actor in the game, we will use a function called Sp awnActor. To do
this, perfor m the following tasks:
a. Branch off a wire from the S pawn Ball custom event we ju st crea te d.
b. Search for a function called Spa wn Actor from Class by typing the
Spawn Actor from Class in the search bar.
c. The class we will be using is our Ball class that we made at the beginning
of the tutorial.
d. Left-click on the arrow next to the Class pin of the Sp awn Actor from
Class and search f or the Ball blueprint.
e. This will connect the Ball class blueprint as the class that the spawner
should spawn.
FIGURE 8.6: Spawner Blueprint Will Spawn Balls at Its Location.
17. Now we will give the spawned objects a Transform so that the function knows
the or ie ntation, location, and scale of the object it will be placing in the level. To
quickly make a transform, per form the following actions:
a. Drag off a wire from the Spawn Transform pin of the Spawn Actor fu nc-
tion to the left and search for Make Tra nsform.
b. For our purposes, we need to feed the loca tion of our blueprint into the
transform location. This will ensure that the ball will spawn at the origin of
our spawner, as well as have the default scale and rotation.
c. Drag off a wire from the Location pin and search for Get Actor
Location.
d. When you pla ce the Get Actor Location in the event gra ph, the Target
should be self which is the current blueprint we are working in.
Advanced Blueprint Concepts 509
18. Your network should look similar to Figure 8.6.
19. Compile and save the blueprint. If you get a compiler error, double ch eck that you
have the class set to Bal l in the SpawnActor Class func tion and that you have
your Make Transform hooked up correctly (see Figur e 8.6 for reference).
FIGURE 8.7: Ball Blueprint with Physics Activated.
MODIFYING THE BALL BLUEPRINT
Next, we will add a mesh to the Ball blueprint we create d earlier.
20. Open the Ball blue print.
21. Navigate to th e Components tab.
22. Left-click o n Add Component, add a Static Mesh to the components list.
23. Rename the static mesh to Ball.
24. Find the Static Mesh section in the Details rollout.
25. Left-click on the drop-down menu and find a mesh called Material Sphere.
This mesh is a part of the starter content.
26. Lastly, we need to en able ph ysics for the ball. Find the Physics section in the
Details rollout and chec k Simulate Physics.
27. As always, remember to compile and save the blueprint.
28. The Ball blueprint should look similar to Figure 8.7.
TESTING OUT THE LEVEL
Now that we have the ball and spawner done, we should quickly test out our
newly created blueprin ts.
29. Place a Ba llSpawner in the level by dragging it onto the screen.
30. With the BallSpaw ner still selected, open the level bluepr int (by clicking
blueprints at the top of the editor and selecting Open Level Blueprint).
510 Game Development and Simulation with Unreal Technology
31. Create an Event Begin Play event and attach it to a Spawn Ball function. This
will create the event call and automatically add a reference to our BallSpawner,
which we h ave plac ed in the level, as the target (see Figure 8.8( a)).
(a) (b)
FIGURE 8.8: Testing the Ball Spawner Blueprint: (a) Level Blueprint. (b) One of the Ball
Spawners Placed in the Level.
32. What this is going to do is spawn a ball at the location of our BallSpawner that
we have placed in the level.
33. This ball will spawn one time as soon as you press play. If your spawner is floa t-
ing above the ground a bit like it is shown in Figure 8.8( b), the ball sh ould im-
mediately simulate physics and fall to the floor. If you walk up to the ball, your
character’s collision box should push the ball as well.
What Happened in TUTORIAL 8.2. . .
We have successfully created a system to be able to spawn an object using a
custom event. This will set us up for the next tutorial where we will cr eate a
system to spawn a single ba ll in a random location in our game field. Keep in
mind that we only spawned a ball fr om a single ball spawner using the event
begin play node. We will be expan ding on this functio nality to spawn a single ball
from a group of ball spawners based on h ow much time has passed. The ball class
will not have much more to it than what we already have in place. Additional
functionality of the ball class will be given to it by the ball spawner class instead.
In the n ext tutorial, we will begin to create our ball spawning sy stem, so the ball
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.60.63