Game development UE4 Adding characters to the scene

Source: Internet
Author: User

And then the last time we went on, now that we have a scene and run, we need to add a character to the scene. To do this, we must inherit it from the Gameframework class of UE4.

I. Creating a class that inherits from the character class

Inheriting from the basic framework class is simple:
1) Open your UE4 editor in the project.

2) in the file, select "New C + + class".

3) Here you can choose to inherit from the pawn class (The pawn class receives input from the controller) or from the actor class. However, we can choose to inherit from the character class (role) here.

4) Click Continue, then you can name this class. Here we'll name it avatar.

5) Finally click Create Class to create this class using code.

6) then UE4 will automatically run your vs project. We open the Avatar.h file in the project solution:

The Avatar.h is this:

Fill out your copyright notice in the Description page of Project Settings. #pragma once#include "gameframework/characte R.h "#include" avatar.generated.h "Uclass () class Myfirstcode_api aavatar:public acharacter{generated_body () public:// Sets default values for this character ' s Propertiesaavatar ();//Called when the game is starts or when spawnedvirtual void is Ginplay () override;//called every framevirtual void Tick (float deltaseconds) override;//called to bind functionality T o inputvirtual void Setupplayerinputcomponent (class uinputcomponent* playerinputcomponent) override;

Both Uclass () and Generated_uclass_body () are UE4 defined macros, and the Uclass () macro makes your C + + code available in the UE4 editor. Generated_uclass_body () will properly handle your class function as a UE4 class. Now you don't need to thoroughly understand how they work, you just need to make sure they appear in the right place.

two. Create a model for the role

Now we avatar inherited the role class, but we also need to give the role a model. We can find free models from the UE4 Mall, the steps are as follows:

1) Click on the market of the toolbar to enter the UE4 mall.

2) Select a role in the category and find a free resource pack named Animation Starter Pack, click to enter.

4) Click on the Free button to add to the library. (May load a bit slowly, wait patiently, I loaded for a few minutes)

5) Click on the Library and click "Add to Project" when finished downloading.

6) In the new window, select Demo1, and then click Add to Project.

7) Now, we can find the resource we just added and click on the select path in the content browser:

8) Select the Animstarterpack folder:

three changing the loaded resource at run time

Load grid Typically, this is a hard-coded bad habit if you use C + + code to specify the resources to load. When you run the program, the program does not change if the resource changes. A better approach is to change the loaded resources at run time.

Here we create a blueprint from the C + + class:
1) In the menu bar window-Developer tools-category viewer.

2) in the Category Viewer, right-click Avatar and select Create Blueprint class. (If you can't find Avatar, close the UE4 editor and reopen)

3) Enter the Blueprint class name below (I'm Bp_avatar here) and click Save. Then you will come to the Blueprint Editor:

4) In the component window in the upper-left corner, select mesh:

5) in the details panel on the right, in the Mesh tab, select the drop-down button, then click View Options, click Show Engine content, and then select TUTORIALTPP.


6) At this time the collision body looks like this, the model and the collision body is not on:

7) Then we use the W, E, R shortcut keys to transform the model so that it is approximately enclosed in the collision body. If the collision capsule is not large enough, you can click on the capsulecomponent of the component and then adjust the capsule size in the shape of the detail panel:

8) Then we can close the window. Drag and drop Bp_avatar into the scene in the content browser.

Four adding animation actions

Adding animations you can see that the character model is a T-shape, and the 3D modeling/animator usually makes the character default hem T-shaped, because this allows the character to make a variety of movements.

1) Double-click the Bp_avatar of the content browser to reopen the Blueprint editor.

2) Click on the viewport in the Upper tab and select Mesh, and select Ue4asp_hero_animblueprint in Anim Blueprint Generated class in the animation option in the details panel on the right.

This completes the animation of a model and adds more details about the animation, which we'll delve into later in the tutorial.

Five Add camera

To make us have a third-person view, we add the camera to the character to follow the role.

1) Perform the following steps in the component:

2) Move the camera and rotate the character to the following status (note that the blue arrow of the character is the direction of the character, so make the camera and the character itself facing the Blue arrow):


3) Click on the toolbar to save.

The roles are not yet under control, and the next section continues with how to write C + + code to control roles.

Game development UE4 Adding characters to the scene

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.