UE3 code reading requirements

Source: Internet
Author: User
Tags wxwidgets
  • Code explanation for Unreal Engine 3
    • Overview
    • Directory structure
    • Engineering Structure
    • Game/engine code
    • Unreal C ++ Standard
      • Object naming rules
    • UnrealScript File
      • Class option Modifier
      • Automatically generate a header file using the native option Modifier
      • Noexport option Modifier
    • UObjects
    • AActor
    • Serialization
    • Configuration System
    • Master Tick (update) loop
    • Conclusion
Overview

This document is for programmers who are starting to use the Unreal Engine for Development. It briefly explains all aspects of the basic code. It is not a complete guide to engines, but a good preparation after you compile the engine code. If you have not compiled your project, visit the: Getting Started Guide or quick start page.

Directory structure

After the basic UE3 code is synced from Perforce, a folder namedUnrealEngine3Directory.

The "UnrealEngine3" folder contains the following directories:

  • Binaries-This file contains binary objects. For example, the compiled engine/game version, the DLL files required by UE3 (Direct X, wx runtime system, etc.), and the editor resource files (icon images ).
  • Development-This is where the source code of the engine actually exists. in this folder, there are:
    • Build-The batch files used to start various types of compilation on our Continuous Integration Server (CIS) [Continuous Integration Server] are stored here. CIS can check compilation for us and capture compilation errors as much as possible.
    • Documentation-Folder for Storing document files. The automatically generated windows Help documentation is stored here (UnrealEngine3.chm ). This help document is a good resource to help you quickly browse the Unreal source code.
    • External-All database source files not from Epic are stored in this folder. For example, libPNG, wxWidgets, zlib, and Cg.
    • Intermediate-All intermediate compilation files are stored here .. Obj file, pre-compiled header file, etc.
    • Src-Source code files and project makefiles. The main UnrealEngine3 solution exists in the folder. This solution also contains folders for each project. An instance project can be subdivided into directories as follows:
      • Game Folder (Game Folder)
        • In the Project Master folder, It is the project's visual studio project file.
        • Classes-Save the. uc (UnrealScript) file folder.
        • Inc-Save the. h file folder.
        • Src-Save the. cpp file folder.
    • Tools-Save all source code folders of various engine-related tools, such as UDE, vistual studio macros (vistual studio macro) and some command line tools.
  • Engine/Game folders-The Binaries and Development folders are followed by the folder Engine, followed by the folders of each game using this Engine.
    • Config-Contains the. ini file used to save the game settings.
    • Content-The folder containing the game content package.
    • Localization-A folder containing any localized Text of the game.
    • Logs-A folder containing the log files generated when the game is running.
    • Script-Contains the compiled UnrealScript code (. u file) of the game ).
Engineering Structure

To isolate the system and help maintain cross-platform compatibility, UE3 is divided into multiple projects.

The basic structure is as follows (from the top-level code to the top-level code ):

  • Core
  • Engine
  • Editor
  • UnrealED

Note that all these projects must be built on each other, which means that the Engine depends on Core, Editor, and UnrealED.

  • Core:Core is the lowest level class, which refers to something similar to string class, array class, Memory Manager and so on. This is where the core script and Loading Code exist.
  • Engine:The Engine folder is a place where rendering and gameplay code exist. It also includes actors, collision detection, and many other subsystems. This is where most 'game interface' code is located.
  • Editor:Editor consists of classes and programs used only when the Editor is running. These classes allow users to operate on polygon, paint brushes, terrain, and other actions that are not normally executed in the game.
  • UnrealED:UnrealED is the real UI Implementation of the editor. This is where the editor application code exists. Currently, wxWidgets is used as our UI tool set. Any wxWidgets code to be written must be put into UnrealED. The concept here is that the 'editor' project contains functional code of all editing tools, while UnrealED is only the UI encapsulation of those functions.

There are also many specific functions for other platforms, such as D3DDrv (Direct 3D rendering implementation) and WinDrv (Windows implementation for creating a view and processing events ). If a project is implemented on a specific platform on a cross-platform interface, it is likely that it requires a suffix Drv.

Game/engine code

The Unreal Engine generally divides game code and engine code into two different programming languages:

  • Engine Code:
    • It is written in C ++.
    • Use the ". h" and ". cpp" extensions and store them in the "Inc" and "Src" folders of the project.
  • Game Code:
    • Use the unique language of the Unreal Engine: UnrealScript. This language is similar to Java in many aspects. For more information, see the UnrealScript reference page.
    • Use the extension ". uc" and store it in the "Classes" folder of the project.
    • Compile before execution.
Unreal C ++ Standard

  • Unreal has defined a set of data types in the engine (INT,FLOAT,UBOOL). These data types should always be used, rather than the standard C ++ data types, to ensure cross-platform compatibility.
  • Unreal uses the wide character (TCHAR). All string characters must be inTEXT()Macros are encapsulated to ensure that they can be correctly converted to wide characters.

Example:

const TCHAR* TestString = TEXT("My Test String");

For more information about the Phantom encoding specification, refer to the encoding specification page.

Object naming rules

It is important to append a letter prefix to the class and struct, because Unreal uses these prefixes to let programmers know how to handle an object.

  • FClassName

    • Instance:FString, FVector
    • Application:Any object with the character prefix 'F' is a standard C ++ struct (struct) and class, and these objects do not have to inherit any other special things.
  • TClassName

    • Instance:TArray, TMap
    • Application:Any object with the character prefix 't' is a template class, and these objects do not have to inherit any other special things.
  • UClassName

    • Instance:UObject, UEngine, UGameEngine
    • Application:Any object with the character prefix 'U' is a class or struct (struct) inherited from UObject ). UObjects is special because they can be automatically reclaimed by the engine. This meansUObject will never be deleted!When they are not referenced, the engine automatically recycles them. This also raises another issue that needs to be addressed by programmers: how to store a reference to a UObject. We solve this problem through serialization. serialization will be discussed later in this document.
  • AClassName

    • Instance:AActor, ABrush, APointLight
    • Application:Any object with the character prefix 'A' is A class or struct (struct) inherited from AActor ). AActor is the basic 'actor 'class. Actors and general uobjects are different because they are played by real locations and real projects in the gaming world. Only actors can copy on the network and use the UnrealScript status. Actors can also inherit UObject and follow the rules that cannot be deleted when an object with a U prefix is applied.
UnrealScript File

This document only briefly addresses some of the issues that a new programmer needs to solve when using the Unreal Engine.

For a comprehensive description of UnrealScript, refer to the UnrealScript Reference Guide page.

Class option Modifier

When declaring a class, you can specify some UnrealScript Classes options. For more information about this function, see UnrealScript Reference Guide: UnrealScriptReference # Class_overview.

In this tutorial, we will briefly cover one of these options, because it can easily make mistakes for programmers who first understand the Unreal Engine.

Automatically generate a header file using the native option Modifier

If you specifynativeThen the UnrealScript compiler will automatically generate a C ++ class declaration for the UrealScript class. These header files have the suffix "Classes", which is generally related to the project name. For example, "EngineClasses. h", "EnginePhysicsClasses. h", and "EditorClasses. h.

Because whennativeThe UnrealScript will automatically generate the C ++ class, so the programmer should be careful not to modify the automatically generated header file, but to modify it in the. uc file.

Noexport option Modifier

Some classes arenativeAt the same timenoexport. These classes cannot automatically generate the corresponding C ++ part, but still expect the C ++ declaration to exist. Therefore, programmers must write a header file by themselves. There are many examples of this situation in the engine (see UEditorEngine in the Development/Src/Editor/Inc/Editor. h file ).

noexportThe UnrealScript class must be 'synced 'with the corresponding part of their C ++ '. Therefore, when modifying UnrealScript files, the programmer should be careful.

For more information about native class compilation, refer to Native class compilation.

UObjects

Because UObjects is automatically managed by the engine, there may be some unique minor differences that new programmers are not familiar:

  • UOject never usednewCreate, but useConstructObjectTemplate Function.
  • UOject never useddelete. The garbage collector automatically deletes UObjects.
  • UObject::StaticClassIt can be used to obtain a pointer to any UObject static instance.
AActor

The Unreal World object contains a list of all its internal Actors.

  • UnavailablenewOrConstructObjectTo create AActors-you should useSpawnActorFunction.
  • To destroy an Actor, useDestroyActorFunction.
  • AActors can contain a group of UActorComponents. These are useful objects that provide small, orthogonal Unit functions. This allows a light source, particle system, and sound effect.

Serialization

A powerful feature of the Unreal Engine is that it can automatically serialize all UObjects attributes defined in the. uc file by name. This allows you to change the order of attributes, add new attributes, and move attributes in the class hierarchy without compromising backward compatibility.

The Unreal garbage collection system uses serialization to determine which UObjects isAvailableTherefore, make sure that you have serialized references to any UObjects that you do not want to clear. Creating a tool in the editor may cause problems. We generally inherit from the FSerializableObject interface, which provides a = Serialize = function that can be saved to the reference of UObjects created in the tool by implementing this function.

void FSomeTool::Serialize(FArchive& Ar){    Ar << SomeUObjectPointer;}

If you use native serialization tools to serialize permanent data, you must explicitly support serialized data of earlier versions. To enable this function, two versions are stored in each package, one for the engine and the other for authorized users. When the authorized user changes the serialization, it can updateGPackageFileLicenseeVersionAnd will be checked during deserializationAr.LicenseeVer()To determine the version of the sequence for data storage.

Configuration System

UE3 uses a hierarchical configuration system, which means that the default value isBase)And the subclass can overwrite the configuration files of these base classes.

All configuration files are. ini files and follow special naming rules:

  • The base class configuration file is placed in the UnrealEngine3 \ Engine \ Config folder, and the file name has a prefix wordBase.
  • Each file has its ownConfigFolder and a group of. INI configuration files. The prefix of these files is the name of the game that owns them.

For example, the structure of the Editor configuration file is:

  • Engine \ Config \ BaseEditor. ini

    • Ini file of "ExampleGame": ExampleGame \ Config \ DefaultEditor. ini

      • Ini file of "ExampleGame": ExampleGame \ Config \ ExampleGameEditor. ini

This system is powerful because it is also used to fill data with the attributes defined in the script, and these script attributes can be used to quickly configure any part of the game.

Master Tick (update) loop

The master Tick loop of the engine can be found in the LaunchEngineLoop. cpp file:FEngineLoop::Tick(). This function calls the UEngine classTickFunction, which updates the game world and monitors other subsystems of the update engine.

For details about how Actor ticking (update) function works, refer to the Actor Update page.

Conclusion

Unreal Engine programming is daunting at first glance, but over time, you will begin to understand that some complicated design decisions make it look like today. Now that you have learned the first quick tutorial of Unreal Engine programming, please visit other technical resources provided to programmers on UDN.

Here are some useful pages for beginners:

Unreal Engine encoding specifications:

Code Specification

How to Use ExampleGame to create a new game project:

ExampleGame Guide

How to track your memory applications in ue3:

Memory usage

How the actor update loop works:

Actor update

UnrealScript Reference Guide (this is a required page ):

Unreal script Overview:

For more information about the compilation mark as 'native 'class:

Compile Native classes

Frequently Asked technical questions about the Unreal Engine (FAQ ):

FAQs

ClassificationForm
Relevant topics UnrealScriptTopics, GettingStartedTopics, and TechnicalTopics
Engine build None/All
Applicable platforms
Document availability UE3Licensees
Access required
Origin CodeOrientation
Revision 1.11
Language Zh

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.