官术网_书友最值得收藏!

Editing and adding code

After opening Visual Studio, you will have the base code for the header file and the sources file of the character class we just created. This base code is not essential; you can edit it or remove the majority of it, but for our game's purposes we will keep it.

The header file will usually look like this by default:

As you can see, header files start with including the character header file from the Unreal Engine game framework, and then include the generated header of the newly created class we just made.

An Unreal Engine class should have the macro UCLASS above it, otherwise you will probably get a compiler error.

The class, by default, will include several public functions that are, in order:

  • Constructor: This is necessary to hold any code that is used to build the class (or any blueprint based on that class) during edit time
  • BeginPlay: The override of the virtual void BeginPlay class, which is going to be called once the game starts
  • Tick: This is also an override of a virtual void from the base class, and that method will be called every frame as long as the object exists
  • SetupPlayerInputComponent: Another override of a virtual function from the base class, and this one is called to set up and map the key inputs (the ones we made in Chapter 1, Preparing for a Big Project) to the class

In addition, the source file for the Gladiator class should have all the implementations of those functions defined within the header file.

The base code of the source file is almost empty; it is just declarations for the methods. But one thing to notice here is that the object constructor contains a Boolean value named PrimaryActorTick.bCanEverTick; setting it to true will make sure this object and all its instances use the tick function (called every frame). So if your class is not going to call a tick, or you want an easy way to disable a tick for a class and its objects, just mark this value as false.

主站蜘蛛池模板: 乌拉特后旗| 英超| 盐源县| 山东省| 儋州市| 晴隆县| 蒙城县| 景德镇市| 澄江县| 邵阳县| 三门县| 收藏| 苍南县| 上虞市| 达尔| 大余县| 广宗县| 浦北县| 九台市| 林周县| 安国市| 文登市| 榆社县| 射洪县| 双流县| 呼伦贝尔市| 资溪县| 襄垣县| 无棣县| 中江县| 临夏县| 旅游| 繁峙县| 乌拉特后旗| 宜兴市| 许昌市| 西峡县| 华阴市| 扶余县| 泗洪县| 辽阳县|