In this series, I am trying to use blogging as a motivation to continue learning the unreal engine. Naturally, one downside to that is that I may figure out better ways of doing something as I gain more perspective. I will do my best to update these posts as I learn more. Also feel free to comment below if you have any ideas or know a better way of doing something. I will try to include anything I believe helps the learning process. Currently I am using version 4.7.6 of Unreal Engine 4. If you find yourself using a new version you might have to figure out how to accomplish the same functionality in that version.
Plan
- Create Player Blueprint
- Add Camera Boom
- Add Camera
- Setup Scene
- Change Instance of a Blueprint
Project Setup
Lets create a new Blank Blueprint Project. I am calling my project MyTwinStickShooter. I am creating my project as a Mobile/Tablet with Scaleable 3D or 2D. I am doing this because I am running this on a Macbook Pro that can’t handle the features that Unreal pushes out for Desktop/Console. If you machine can handle more than feel free to upgrade the settings.
Right now we have a great starting point for a first person game. Not super helpful. Also note that I could have started with the Twin Stick Shooter template but what’s the fun in that? When I am learning I like to do it the hard way mainly because I like to know how things work.
Player Setup
Lets create folder called Blueprints. Right click in the Content Browser or click Add New then select New Folder. Name it Blueprints.
Go into the Blueprints folder and click Add New then Blueprints Class.
If you are coming from Unity, blueprints are kind of like prefabs. I say “kind of” because in Unity you usually make a prefab after you make the first iteration and then want to duplicate it. With Unreal it seems that an think you want to add code to is a blueprint. From what I have experienced so far this would be the equivalent to taking each top-level item in a Unity Hierarchy and making them into a prefab. Also by default the Components (Hierarchy) you create in a blueprint is not exposed to the World Outliner. So, unlike Unity, dragging things inside and outside of prefabs/blueprints is not possible. It’s pretty logical when you think about the structure of unreal but it is a difference.
Select Character as the Parent class for our blueprint. And name the newly created blueprint MyPlayer.
Let’s now open the MyPlayer blueprint and start changing the default values. Double click to open the blueprint. Now in my version of unreal it opens straight to the Class Defaults section and as an option to go to Open Full Blueprint Editor. Since we will be affecting the structure of this component I am going to go ahead and click that link.
Make sure you are in the Viewport tab so you can see the changes as you update the components. Then in the Components panel select Mesh(Inherited).
Now on the right side in the Details Panel scroll down to the Mesh group (not the Skeletal Mesh group) and click on the drop down for Skeletal Mesh. For me the drop down is empty. I am not currently planning on doing an art pass on this project, so I want to keep things as simple as possible. All I need is a cube. It just so happens that the engine content has a skeletal mesh that is a cube. So let’s enable engine content. The window that showed up when you clicked the drop down for the skeletal mesh is the Current Assets window. At the bottom right corner of the Current Assets window select View Options and make sure that Show Engine Content is checked. Once this is checked you should now be able to select SkeletalCube.
Now you may see your cube is a little small for your collider so lets position and scale it to fit. Copy the values from the Transform group show in the picture.
Let’s go ahead and add a camera so we can see our new player. This is a temporary camera because I want my camera for this game to be slightly smarter. So for now we will add a boom to the character and attach a camera to that boom.
Still in the MyPlayer blueprint make sure you are still looking at the Viewport to see how the changes affect the blueprint. Over in the Components panel click + Add Component and search for Spring Arm and add that component. Rename the Sprint Armto CameraBoom. Set the rotation for the CameraBoom to y: -50.
Next we need to add the Camera. So repeat the steps to add component and search from camera. Drag the Camera on top of the CameraBoom so that the Camera is parented to the CameraBoom. Then make sure you set all of the Transform values to default.
Your Components panel should now look something like this:
And your viewport like this:
One last note before we can test this sample, is that we need to make sure that if we put this player in the scene he will be the player that the system uses. Select MyPlayer(self) in the Components panel. Then in the Details panel under Pawn look for Auto Possess Player and set it to Player 0.
Now would be a great time to compile and save the blueprint. Then you can close the blueprint tab.
Scene Setup
Now that we have our player setup lets make sure the scene is setup and knows about our player.
Just to make sure we are in the same place we start with the Default Level. To do that select File -> New Level. Select the one that says Default.
First off I want the floor to be bigger so I am going to select the Floor in the World Outliner panel and change the scale to x: 10, y:10, z:1
Next let’s get rid of the PlayerStart actor because we don’t currently want to dynamically add our player. Instead, we are going to have him already in the scene. Right click on PlayerStart in the World Outliner and select Edit->Delete.
I am doing it in this way because it make more since to me at this stage and correlates to my understanding coming from Unity.
All that is left is to add MyPlayer to the scene. Drag MyPlayer blueprint into the scene. Unreal automatically snaps him to the floor so all we need to do is change his x and y position to be in the middle of the floor.
Lets hit play and see what we have. Now this doesn’t do much because we haven’t added any functionality. It is just a simple scene. So it looks something like below. (If you need to exit play mode you can always hit escape)
Well that’s all good and all, but let’s make it a bit easier to look at. Make sure you stop the simulation and open the MyPlayer blueprint (remember you can hit escape to exit play mode). Select the Mesh(Inherited) and under the Details panel. In Materialsgroup click the drop down and select BasicAsset01.
I also want to have the camera be further back so lets increase the length of the boom. Select CameraBoom and set the Target Arm Length to 1000. Compile and Save and close the blueprint tab.
Now you will notice that your player in scene doesn’t reflect our new changes. This is because it is an instance. You will have to reset it to the blueprint for it to work. Make sure you have MyPlayer selected in the World Outliner panel and in the Details panel there is a blue dropdown that says Edit Blueprint. Select Reset Instance Changes to Blueprint Default,and now your instance use the correct material.
I think that is a good start to the tutorial. Make sure you save your scene. I saved my as MyLevel.
Summary
We covered creating a player blueprint that has a camera with boom attached. Set the player in a simple scene. We also demonstrated how to update blueprint instances. Let me know what you think and next time we will get into movement. Also let me know if I am being too detailed or not detailed enough.