Unity 過度到 Unreal 4 對比參考 非常詳細!

原文地址:http://demo.netfoucs.com/u011707076/article/details/44036839


前言

        

        寒假回家到現在已經有十多天了,這些天回家不是睡就是吃....哎╮(╯▽╰)╭,今天早上一覺醒來,突然得知,UE4免費了,這絕對是個好消息,前不久我還在糾結怎麼申請校園賬號呢o(╯□╰)o。迫不及待打開電腦下載了UE引擎的一個類似管理的客戶端,在裏面最醒目的一欄,看到一個令人哭笑不得的導航,如下圖:

  

       EPIC這是要逆天的節奏嗎?不過不管他了,接下來,我們便一同學習一下EPIC提供給我們的這篇從Unity過渡到UE4的經驗之談吧。說明一下,下面我將對這篇文章中的重點內容做翻譯和一些自己的見解,僅供參考,若需更詳細的內容,請訪問官方提供的文檔手冊。

      原文目錄:https://docs.unrealengine.com/latest/INT/GettingStarted/FromUnity/index.html?utm_source=uelauncher&utm_medium=software&utm_campaign=learntab


那我們就開始吧

The Editor  編輯器

兩個編輯器的佈局如下:



Editing Assets編輯資源


Detail面板就是負責編輯工程資源,類似於Unity裏面的Inspector。


Quick Glossary(Glossary:術語)

 兩個引擎的部分術語對比:

Category Unity UE4
Gameplay Types Component Component

GameObject ActorPawn

Prefab Blueprint Class
Editor UI Hierarchy Panel World Outliner

Inspector Details Panel

Project Browser Content Browser

Scene View Viewport
Meshes Mesh Static Mesh

Skinned Mesh Skeletal Mesh
Materials Shader MaterialMaterial Editor

Material Material Instance
Effects Particle Effect Effect, Particle, Cascade

Shuriken Cascade
Game UI UI UMG (Unreal Motion Graphics)
Animation Animation Skeletal Animation System

Mecanim Persona , Animation Blueprint
2D Sprite Editor Paper2D
Programming C# C++

Script Blueprint
Physics Raycast Line Trace, Shape Trace

Rigid Body Collision, Physics
Runtime Platforms iOS Player, Web Player Platforms

Projects and files工程和文件

So what are all these directories and files?工程目錄和文件的具體內容?

Just like Unity projects, Unreal projects always exist in their own directory and have their own project file. You can double-click on .uproject files to load your game into the Unreal Editor, or right click for additional options. Project folders have various sub-folders that contain your game's content and source as well as various configuration files and binaries. The most important are the Content and Source sub-folders.就像Untiy的工程一樣,Unreal4的每一個工程都有他們單獨的工程文件夾。可以通過雙擊.uproject 文件打開工程,或者通過右鍵查看更多選項。UE4的工程文件夾包含很多子文件夾和文件,裏面最重要的是Content和Source 文件夾。

Where do I put my assets?我應該把資源放在那裏?

In UE4, each project has a Content folder. Similar to a Unity project's Assets folder, this is where your game assets are stored. To import assets into your game simply drop files into your project's Content directory and they will be automatically imported and appear in the Content Browser. The assets in the editor will update automatically as you make changes to the files using an external program.UE4的工程文件夾裏面的Content文件夾和Unity的Asset文件夾類似,用來存放遊戲資源。可以通過拖拽的方式,載入資源,對資源進行處理過後,UE4工程將會自動在Content文件夾和ContentBrowser面板中更新資源信息。


What common file formats are supported?支持的文件格式

UE4所能支持的一些文件格式

Asset Type Supported Formats
3D .fbx, .obj
Texture .png, .jpeg, .bmp ,.tga, .dds, .exr, .psd, .hdr
Sound .wav
Fonts .ttf, .otf
Videos .mov, .mp4, .wmv

How is my Scene stored?場景文件是如何存儲的呢?

In Unity you place GameObjects in a scene and save that as a Scene asset file. Unreal has a Map file that is similar to a Unity Scene. Map files store data about your Level and the objects in it, as well as lighting data and certain level-specific settings.Unity中我們把GameObject放置到場景裏面,並以場景資源的形式存儲。在UE4的工程中Map文件類似於Unity中的Scene文件。Map文件存儲了關卡里面的物體,同樣的包括光照信息,和關卡本身特定的屬性。

How do I change my project's settings?如何更改工程設置

All project settings can be found from the main menu under Edit / Project Settings. Like Unity's project settings, these allow you to specify information about your project (such as project name and icons), configure game input bindings, and define how the engine behaves when running your project. You can learn more about individual project settings here. Unity also has what's called "player settings". In Unreal, these are "platform settings", and can be found under the "Platforms" category in your project settings.

可以在Edit / Project Settings 工程設置中更改工程的名字啊,圖標啊,設置輸入的綁定信息啊,定義引擎如何在你的項目中運行,還可以選擇平臺。

Where do my source files go?源文件是如何運行的

In Unity you're accustomed to placing C# source files in your assets folder.在Unity中,我們習慣於把C#文件放置在資源文件夾Assets裏面。

UE4 works differently. For projects that have C++ code, you'll find a "Source" sub-folder under the project directory that has various files, including C++ source (.cpp) and header (.h) files, as well as some build scripts (.Build.cs, .Target.cs) However, Blueprint-only projects won't have a Source folder.但是UE4卻不是這樣的。對於用C++創建的UE4,你將會在遊戲工程文件夾下找到Source子目錄,裏面存放了包含.h,.cpp和各種文件。然而通過藍圖創建的工程沒有Source文件夾。

The easiest way to get started with C++ in UE4 is to use the editor to Add Code to Project (in the main File menu), or to simply create a new C++ project from scratch from one of the many templates. You can find C++ classes right in the Content Browser and can open the files in Visual Studio or Xcode by double-clicking on their icons.UE4中開始使用C++最簡單的方式是通過編輯器中的 Add Code to Project 命令。或者通過C++工程模板創建的工程只需要在ContentBrowser裏面雙擊代碼就可以用VS打開了。

From GameObjects to Actors 從GameObjects到Actors

Where Is My GameObject?Unit中GameObject在UE4中如何體現?

In Unity, a GameObject is a "thing" that can be placed in the world. The UE4 equivalent(等價) is an Actor. In the Unreal Editor, you can drag a new Empty Actor into the viewport from the Placement panel:

在Unity中,GameObject是一個可以放置在世界裏面的東西。UE4中的Actor與之等價,在編輯器裏面,我們可以拖放一個空的actor到世界裏面。


You could build a game out of Empty Actors, but UE4 also includes special(特定的) types of Actors with built-in features, such as a Pawn (for players or AI objects), or Character (for animated creatures.) Just like Empty Actors, you can drop these special types of Actors down, then add or customize their properties and components. You'll learn more about it later, but for now try to remember that UE4 has a Gameplay Frameworkthat works with these special Actors.

你可以使用一個空的Actor來創建自己的遊戲,但是UE4內置了很多有特定功能的Actor類型,比如Pawn(是針對players和AI角色),Character(針對有動畫的生物)。和普通的空Actor一樣,我們可以拖拽這些Actors到場景試圖,並且定製他們的屬性和組件。稍後我們將學到這部分內容,但是最重要的是記住,UE4有一個 Gameplay Framework 系統來使用這些Actors工作。

Actors in UE4 are a bit different than GameObjects in Unity. In Unity, GameObject is C# class which you can't directly extend. In UE4, Actor is a C++ class which you can extend and customize using inheritance. We'll talk about this more later on!

UE4中的Actors和Unity中的GameObject有很多不同。Gameob是C#的類,不可以直接擴展。而在UE4中,Actors是c++的類,你可以擴展並且拖過繼承的方式自定義。稍後我們將繼續學到這部分內容。

Where Are My Components?Unity中的組件在UE4中如何體現?

In Unity, you add components to a GameObject to give it functionality.在Unity中我們可以通過給一個物體組件來給他添加功能。

In UE4, you add components to Actors. After you've dropped an Empty Actor in your level, click the Add Component button (in the Details panel) and choose a component to add. Here, we're creating a torch by dropping an empty actor, then adding a mesh component for the base, followed by a light source and then a particle system to create its flame.空物體--添加組件(mesh、light、particle )製作火把,看下圖即可

1.拖放空Actor,爲其添加StaticMesh組件

  


2.在Mesh組件的層級上,添加點光源組件


3.Mesh上添加例子Particle組件




In Unity, a GameObject hold a flat list of components, but in UE4 an Actor actually contains a hierarchy of components attached to one another. You can see this in the example above, where the Light and Particle are attached to the Mesh. This has some important implications discussed later in Complex Actors and GameObjects.

Unity中一個GameObject的所有組件的關係是平行的,但是在UE4中,一個Actor的組件之間可以存在層次關係。如上面火把的例子中,Light和Particle組件就是依附在Mesh組件上。等下將會在Complex Actors and GameObjects這一節中討論更多重要的概念。

From Unity prefabs to UE4 Blueprint Classes  Unity中的prefabs對應UE4中對應藍圖類

Unity's workflow is based on prefabs. In Unity you build a set of GameObjects with components, then create a prefab from them. You can then place instances of the prefab in your world, or instantiate them at runtime.

Unity的工作流程是基於prefabs的,我們創建一系列具有組件的GameObjects,然後通過他們創建預設,然後我們就可以拖放一個實例到世界中或者在運行的過程中動態生成實例。

UE4's corresponding workflow is based on Blueprint Classes. In UE4, you build an Actor with components, select it, and click the "Blueprint / Add Script" button (in the Details panel). Then, choose a place to save your Blueprint Class, and click "Create Blueprint" to save your new Blueprint Class!

UE4中相對應的工作流程是基於藍圖類的。在UE4中,你可以你可創建一個擁有組件的Actor,選中它,並且在Details面板中點擊 "Blueprint / Add Script"按鈕,然後選擇一個位置存放藍圖類,最後點擊保存。


Your new Blueprint Classes can be found in the Content Browser. You can double-click to edit them directly, or you can drag and drop them into any level.我們新創建的藍圖類可以再Content Browser面板中找到,我們可以通過雙擊他們直接打開,並且我們可以把它們拖放到任意的關卡之中。

Where is Script Component and MonoBehaviour? Unity中的腳本組件和MonoBehaviour中在UE4中如何體現?

In Unity you have Script Components that you drop on GameObjects to add C# scripting. You create a class that inherits from MonoBehaviour to define what that component does.

在Unity中,我們可以給GameObject添加C#腳本,這個腳本繼承自MonoBehaviour 來定義組件的功能。

UE4 has something similar. You can create whole new Component classes of your own and drop those onto any Actor. You can create Component classes using either Blueprint Scripting or C++.

So how do you create your own component class in UE4? In the Detail panel's Add Component drop-down, you see you can create new components, or choose existing ones:

UE4中也有一些類似的東西。我們可以創建完全空的組件並且把它們賦給Actor(對比Unity中需繼承MonoBehaviour )。我們可以通過C++或者藍圖的形式創建組件。在UE4中如何創建自己的獨有的組件呢?答案是在Detail面板中的 Add Component 下拉選項中,我們可以創建新的組件或者選擇已有的組件。


In Unity, when creating a new MonoBehaviour you, will be given a skeleton(概要?) class file with a Start() function and an Update() function.

在Unity中,當我們創建一個新的MonoBehaviour 時,會提供給我們一個包含Start()函數和Update()函數的類。

In UE4, you will also be given a skeleton class with a InitializeComponent() function and a TickComponent() function, which perform functions similar to Start and Update.

If you create a Blueprint Script Component you will be given these same functions as visual nodes:

在UE4中,系統也將提供給我們兩個函數,他們分別是 InitializeComponent() 函數和 TickComponent()函數,這兩個函數和Unity中Start()函數和Update()函數類似。當我們創建一個藍圖腳本組件的時候,系統也將提供給我們兩個具有類似功能的可視化節點。


Scriptable Actor Blueprint Classes 可以編輯的Actor藍圖類

Here is a cool feature in UE4: Your new Actor Blueprint Class can have its own Blueprint Visual Scripting! This allows you to add logic to an entire object, not only an individual component. Combined with inheritance (explained below), this gives you a lot of flexibility when designing your game.UE4中有一個非常酷的功能:你新建的 Actor藍圖類(此處不是組件藍圖類)可以使用藍圖來實現可視化編輯。這意味着你可以對整個物體添加邏輯,而不僅僅是這個物體中一個特定的組件。這將在你設計自己的遊戲中提供更大的靈活性。

In addition to Blueprint Classes supporting visual scripting, UE4 also supports C++ Classes implemented with code. Here are both, side-by-side.

除了可以可視化編輯的藍圖腳本之外,UE4也支持通過代碼實現功能的C++類。下面給出了三個的對應關係。

Unity c#

  1. using UnityEngine;using System.Collections;public class MyComponent : MonoBehaviour{    int Count;    // Use this for initialization.    void Start ()    {        Count = 0;    }    // Update is called once per frame.    void Update ()     {        Count = Count + 1;        Debug.Log(Count);    }}  
UE4 C++

  1. #pragma once#include "GameFramework/Actor.h"#include "MyActor.generated.h"UCLASS()class AMyActor : public AActor{    GENERATED_BODY()    int Count;    // Sets default values for this actor's properties.    AMyActor()     {        // Allows Tick() to be called        PrimaryActorTick.bCanEverTick = true;      }    // Called when the game starts or when spawned.    void BeginPlay()    {        Super::BeginPlay();        Count = 0;    }    // Called every frame.    void Tick(float DeltaSeconds)    {        Super::Tick(DeltaSeconds);        Count = Count + 1;        GLog->Log(FString::FromInt(Count));    }};  
UE4藍圖


UE4 Blueprint Classes can be extended。  UE4的藍圖類可以被擴展

Unity prefabs and UE4 Blueprint Classes can be instantiated in your game similarly. However, Unity has complications related to nesting prefabs within other prefabs, which limit their role as extensible building blocks.

In UE4, you can create a new Blueprint Class which extends an existing Blueprint Class and augments it with new properties, components, and visual scripting functionality.Untiy的prefabs預設和UE4的藍圖類能夠在你的遊戲中相似的實例化出來。然而,Unity有一些併發機制,他們和預設與預設之間的嵌套相關,這些機制決定或者說限制了他們成爲可以在構建時被擴展(這兒有點難理解,看下面的例子吧)。

For example, in UE4 you can create a Blueprint Class named Monster(怪物) which implements basic monster functionality such as chasing people. You can then create further Blueprint Classes which extend it, such as Dragon (a type of Monster which adds fire-breathing features), Grue (a Monster which is likely to eat you when it's dark), and for example 8 others. These subclasses of Monster all inherit the basic functionality from Monster, and add new capabilities on top.

例如,在UE4你可以創建一個命名爲怪物的藍圖類實現基本功能, 比如追趕人類。然後您可以創建更多的藍圖類來擴展它,如龍怪物(對其添加噴火的功能),雪怪(一中可以再黑暗的時候吃掉你的怪物),和其他八種怪物等等。這些怪物的子類都是從一開始創建的有基本功能的怪物類繼承而來,並在其基礎上添加新功能。

In Unity, you would implement this by creating many different GameObject prefabs: one for Dragon, one for Grue, and so on. Now, say you want to add some new functionality to all monsters, such as the ability to speak using your new Speak Component. In Unity, you have to Go and update all 10 prefabs to individually copy and paste the new functionality into it.

在Unity中,你的世界通過創建不同的GameObject實例(比如一個作爲龍怪,一個作爲雪怪等等)來實現這一功能。現在,如果你想給所有的這些怪物添加一些新的功能,比如使用你新創建的Speak組件讓他們有能力說話,在Unity中,你不得不對這十個實例單獨的更新,來爲它們添加功能。

In UE4, you can simply modify the Monster Blueprint Class to add this new ability to speak. That's all! Dragon, Grue, and the 8 other subclasses of Monster automatically inherit the new speaking functionality, and you don't need to touch them.

在UE4中,你可以簡單的修改最初的父類怪物藍圖腳本類添加新的說話功能,僅僅這麼做就夠了,無論是龍怪,雪怪或者其他八種Monster父類的子類都會自動的繼承新的說話的功能,你都不用去單獨的指定它們。

But there's more! Everything we have said here about Blueprint Classes also applies to C++ Classes, and everything is equally true of actors and components. These systems are designed to support large-scale development of extensible functionality, and can scale to projects with 10's or 100's of developers.但是不止如此,我們在這裏說的一切藍圖類也適用於c++類,包括組件和Actor類。這些系統是爲了擴展而被設計的,包括開發大規模可擴展的功能,以及項目開發10人到100人的開發人員人數的擴展。(一字一字的翻譯就是:“這些系統是爲了用來支持大規模開發可擴展的功能,並且可以擴展項目10或100的開發人員所設計的”,反正就是這麼一個意思,容易擴展)。

Should I use Blueprint Scripting, C++, or both?我應該使用C++,藍圖還是都使用呢?

Blueprint Visual Scripting is ideal for simple in-game logic flow and sequencing of actions. It's a great system for designers, artists, and visually-oriented programmers, because it's easy to access and control in-game objects visually. You can even create small standalone-game using just Blueprints; see the Tappy Chicken sample for a full-fledged example.藍圖這種可視化的編輯腳本對於簡單的遊戲邏輯和一些簡單操作的排序是理想的。對於設計者,藝術家和一些以視覺爲導向的程序員來說,藍圖腳本是一個非常棒的系統,因爲我們可以非常方便通過可視化的方式實現和控制遊戲物體。甚至,你可以僅僅使用藍圖來創建小的單獨的遊戲。可以參考Tappy Chicken例子來查看這部分的具體實現。

C++ programming is for larger-scale tasks, such as building gameplay systems, complex AI, and new engine features. If you already have some C++ experience, check out the Introduction to C++ Programming in UE4 page.C++編碼是用來做一些大規模的任務的,比如創建遊戲的框架,複雜的AI和一些新的引擎的功能。如果你有一些C++的經驗,可以之間去查看 Introduction to C++ Programming in UE4 這一頁。

Most projects will use a mix of Blueprints and C++. Many developers prototype game functionality using Blueprints, because it is so easy and fun, and later move some or all of it to C++ for performance and engineering rigor.大多數的工程會混合使用藍圖腳本和C++腳本。許多開發者願意使用藍圖腳本規範遊戲的功能,因爲它非常簡單有趣,然後不就考慮到規範,和性能問題,會把其中的一部分甚至全部移植到C++程序。

Blueprint Classes can extend C++ Classes 藍圖類可以用C++類擴展

Much of the magic of UE4 game development comes from the interplay between programmers implementing new features in C++, with designers and artists utilizing them in Blueprints and then asking for more! Here's how a team might structure a UE4-based shooter game implementing pickups using a mix of C++ Classes systems programming, and Blueprint Classes for behaviour and appearance:UE4遊戲開發的魔力來自藍圖腳本和C++腳本的共同作用。程序員使用C++實現新功能,設計師和藝術家在藍圖腳本中使用它們,實現新的功能,在需要新功能時再向程序員提出。下面是一個實例,展示了一個團隊如何同時使用C++構建一個射擊遊戲的框架,使用藍圖類用來實現具體行爲和一些外觀等功能。

  

Transform Components  Transform組件

In Unity each GameObject has a Transform component, which gives the GameObject a position, rotation, and scale in the world.

在Unity中,每一個GameObject都有一個Transform組件,它賦予了GameObject在世界裏的位置、旋轉和縮放屬性。

Similarly in UE4, Actors have a Root Component, which can be any subclass of Scene Component. A Scene Component gives the Actor a location, rotation, and scale in the world which is applied hierarchically to all components underneath it. Many of the components that you'll use are subclassed from Scene Component, because it's really useful to have a position!同樣的在UE4中,Actors有一個叫做RootComponent的組件,它可以是場景組件SceneComponent的任意一個子類。場景組件使得Actor在世界中擁有位置、旋轉、縮放屬性,而這些Acotor和屬性是在Scene組件之下分層出現的。

Even if you place an Empty Actor, UE4 will create a "Default Scene Root" for that actor, which is just a plain(樸實無華,樸素) Scene Component. If you drop a new Scene component in of your own, it will replace the Default Scene Root.甚至,如果當你放置一個空的Actor,UE4都會爲他創建一個沒有其他特殊功能的默認的SceneRoot。如果你爲它添加了一個新的自定義的場景組件,這個組件將會取代默認的SceneRoot。

Compound Objects 複合物體

In Unity, you create compound objects by constructing a hierarchy of GameObjects and parenting their transforms together:

在Unity中,你可以通過構造GameObject層級關係並且聯合它們的transform屬性來創建複合物體。


In UE4, you create compound game objects by nesting components hierarchically:

在UE4中,我們可以通過按照層級關係嵌套組件的方法來創建複合物體。


As you can see from the diagram, nested hierarchies can be created by attaching Scene Components to one another, since they have a transform - similar to parenting transforms in Unity. Actor Components (the base-class for all components) can only be attached directly to the Actor itself.就像圖標中展示的一樣,我們可以通過不斷添加SceneComponent的方法來創建嵌套的層級關係,Actor組件(所有組件中最基礎的組件)可以直接添加到Actor物體本身上。

Do I build everything out of Components?  我是通過使用各種Components來創建任何東西嗎?

Its really up to you, but most often you'll use a combination(組合) of custom component types along with actor classes that use those components. We mentioned this earlier, but UE4 has many special types of Actors that guarantee(保證) a certain level of capability and always include certain components. For example, a Character always contains a Character Movement Component.這就要看自己的使用習慣了,但是最常規的方法,是結合Actor類的功能使用一些常規組件的組合。我們之前就提到過,但是Ue4也內置了很多特定類型的Actor,他們保證這些Actor擁有制定的功能並且包含了所需的組件。比如說,Character 這個Actor會包含Character Movement Component組件。

There are several sub-classed Actor types you'll quickly encounter(遇到) in the engine and are useful in almost every type of game. Here's a list of our most common built-in Actors:在UE4的引擎裏你馬上會遇到很多特定的Actor的子類,無論對於什麼類型的遊戲他們都是非常重要的,下面列出的是非常重要的內置Actor:

  • Pawn - A type of Actor representing a controllable game object, typically the player's avatar. Pawns are moved by Players and AI alike through an owning Controller.

               - Pawn代表的是一種可以被控制的遊戲物體,對於玩家和AI他們通過自己獨有的Controller來移動。

  • Character - A more specialized version of Pawn designed for biped avatars that handles a lot of the complexity of those kinds of game objects.

                - Character是Pawn的一個專門的版本,是針對能掌控各種複雜物體的人形動物設計的。

  • Controller - Possesses and controls a Pawn. By separating the Pawn from the controller, you can write AI Controllers that can manipulate a pawn using the same interface the player would.

                - Controller 擁有並控制一個對應Pawn,通過把Pawn從controller中分離出來,我們可以寫一些AI的控制使用相同的藉口操縱pawn。

  • Player Controller - A more specialized Controller designed for getting input from a player's Gamepad, Touch, or Mouse/Keyboard, and using that input to drive the Pawn or Character they possess.

                - 是一種特殊的Controller,它可以接收用戶輸入來控制他們所擁有的Character或者Pawn。(就是我們可以控制的)

So is everything an Actor?  難道所有的東西都是Actor嗎?

Not everything. Actors are most common class used for gameplay in UE4 and the only type that can be Spawned into the World. So everything you place in your level will be an Actor.並不是這樣的,Actor是UE4中用來作爲遊戲設置最常規的並且唯一一個可以在世界中生產的類,所以你在關卡中放置的物體都是Actor。

The other important type to know about is Object. Object is actually the base class of all Unreal classes, including Actor and many others. This is a much lower-level construct than Actor, but still has features that you'll expect from a Unreal class, such as reflection and serialization. Object is a very basic class we use when we need to define a new type that just doesn't fit the mold of an Actor. For example, Actor Component is the base class for all Components, and derives from Object instead of Actor.另外一個需要了解的重要的概念是Object。Object事實上是UE4類中最基礎的類,它包含了Actor和其他很多東西,它比Actor更低級的被構造,但是也有一些你需要的功能,比如反射reflection和序列化serialization。當我們需要定義一種新的不符合Actor類型的東西的時候,Object將會作爲一種最基礎的類出現。比如Actor組件就是所有組件中最基礎的類,他就是來源於Object,而不是Actor。

What is this Gameplay Framework thing in UE4? UE4中的GameplayFramework是什麼?

Okay, so this is where things get a little crazy (in sort of an awesome way.) Unity gives you a clean slate to start designing your game, and Unreal does the same. In Unity you can build everything out of basic GameObjects and components, and in Unreal you can build everything out of Actors and components.好吧,這正是事情變得有點瘋狂的時候了(一個很棒的方法)。Unity給你一張白紙開始設計你的遊戲,虛幻也是如此。在Unity中你通過Gameobject和組件來構建所有的需要的東西,同樣,UE4中對應的是Actor和UE4的組件。

However Unreal has this extra layer on top called the Gameplay Framework. This doesn't really exist in Unity at all. You don't have to use it in Unreal, but it's actually super cool! Basically, if you make use of some basic primitive(原始) classes and follow certain established conventions, your game will acquire some awesome features automatically that would be otherwise very difficult to implement or retrofit (such as full multiplayer support!)。然而UE4有額外的上層叫做 Gameplay Framework。在Unity中根本不存在它。你在虛幻中並不需要必須使用它,但是他的功能非常棒基本上,如果你使用一些基本的原始類和遵循一定的既定慣例,你的遊戲將自動獲得一些很棒的功能,否則將很難實現或改造(如多人聯網的支持)。

Countless awesome(極好的) games have been designed on top of Unreal's Gameplay Framework, and its worth taking some time to understand how it works. Yes, you could roll your own version of this. That's totally fine if you want to! But hundreds of awesome Unreal developers have made great use of this framework in UE4 today, so it's worth taking some time to learn.虛幻引擎下很多非常好的遊戲都是基於虛幻的Gameplay Framework這個框架下設計的,我們非常有必要花費一些時間來了解他究竟是如何工作的。是的,你可以使用自己的方法,這是完全沒有問題,但現在數百名很棒的虛幻開發人員使用這個框架的UE4,所以值得花一些時間去學習。

To use the Gameplay Framework, you really just need to learn the customized built-in actor classes included with Unreal, such as Pawn,Character and Player Controller, and eventually learn about how Unreal replication and networking features work. For now, let's get back to the basics though.爲了使用到Gameplay Framework框架,我們必須學習虛幻所包含的一些自定義的Actor類,比如Pawn,Character和Player Controller,甚至學習虛幻是如何工作的,但是現在呢,我們還是回顧整體瞭解一些基本的概念。

How to write code in UE4  如何在UE4中編碼?

So, I'm used to programming in MonoDevelop� 在Unity中我已經習慣了使用MonoDevelop編譯器編碼

For Blueprint scripting you'll only need Unreal Editor -- everything is built in! To write code in C++, download the free version of Visual Studio on Windows, or install Xcode on Mac. When you first create a new project (or add code to an existing project), UE4 will automatically create Visual Studio project files for you. You can open Visual Studio by double-clicking on a C++ class inside Content Browser, or by clicking the "Open Visual Studio" button in the main File menu.

藍圖腳本的編碼是在UE4的編輯器中就可以完成,C++編碼使用最新版的vs。蘋果用戶使用Xcode。如何打開就不用多說了把....(⊙﹏⊙)b


One important difference in UE4: You'll sometimes have to manually(手動) refresh your Visual Studio project files (for example, after downloading a new version of UE4, or when manually making changes to source file locations on disk.) You can do this by clicking "Refresh Visual Studio Project" in the main menu, or by right clicking on the .uproject file in your project's directory and selecting "Generate Visual Studio project files"。有一點得注意,我們有時候需要手動去更新vs文件。(比如下載了新版本的UE4,或者是做了修改)。右鍵點選.uproject文件選中生成文件就行,如下圖。


Writing Event Functions (Start, Update, etc.) 寫事件函數

If you are used to working with MonoBehaviours you are used to such methods as Start, Update, and OnDestroy. Here is a comparison between a Unity behaviour and its counterpart in UE4 Actors and components.

使用Unity我們都清楚一些start(),update(),OnDestroy()這些函數,下面我們就做一個UE4和Unity的比較。

In Unity, we might have a simple component that looks like this:

Unity中簡單的組件看上去張這個樣子:

  1. public class MyComponent : MonoBehaviour{    void Start() {}    void OnDestroy() {}    void Update() {}}  

But remember, in UE4 you can write code right on the Actor than only coding new component types. This is actually very common and useful.

但是請記住,在UE4中,我們可以直接在Actor本身上寫代碼,而不是創建新的組件類型,這非常重要。

Similar to Unity's Start, OnDestroy and Update functions, we have a similar set of methods for Actors in UE4:

UE4中和Unity裏面的那三個函數類似的函數:

C++ :

  1. UCLASS()class AMyActor : public AActor{    GENERATED_BODY()    // Called at start of game.    void BeginPlay();    // Called when destroyed.    void EndPlay(const EEndPlayReason::Type EndPlayReason);    // Called every frame to update this actor.    void Tick(float DeltaSeconds);};  
Blueprint :


Components in UE4 contain different functions. Here is a simple example:

UE4中的組件包含一些不同的函數,下面列舉了一些簡單例子:

C++ :

  1. UCLASS()class UMyComponent : public UActorComponent{    GENERATED_BODY()    // Called after the owning Actor was created    void InitializeComponent();    // Called when the component or the owning Actor is being destroyed    void UninitializeComponent();    // Component version of Tick    void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction);};  
Blueprint :


Remember in UE4 It's important to call the parent class' version of method.

請記住,在UE4中,調用父類的函數的版本是非常重要的。

For example in Unity C# this would be called base.Update(), but in UE4 C++ we'll use Super::TickComponent():

比如說,在unity裏面這樣寫:base.Update();而在UE4中則需要這樣寫:Super::TickComponent();

  1. void UMyComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction){    // Custom tick stuff here    Super::TickComponent(DeltaTime, TickType, ThisTickFunction);}  

You may have noticed some things begin with "A" and others with "U" in C++. The prefix "A" indicates an Actor sub-class. Where as the prefix "U" indicates an Object sub-class. There are some other prefixes too, for example "F" is used for most plain data structures or non-UObject classes.UE4的C++代碼中,字母前綴'A'表示是Actor的子類,'U'表示Object的子類。當然還有一些其他的前綴,比如‘F’,表示是一些空白的數據結構或者不是Object類。

Writing gameplay code in UE4  在UE4中編寫遊戲代碼

Okay, things are going to get a bit deeper from here on out. We'll be talking about programming topics that are critical for creating games. Because you know Unity, we'll be explaining features with slant toward C# users learning Unreal C++, but you can use Blueprint Scripting for pretty much everything if you want! We've added examples in both C++ and Blueprint where possible.

Let's talk about some of the most common gameplay programming patterns and how you'd approach them in Unreal. Many functions in Unity have a comparable function in Unreal that should seem familiar. We'll go through the most common functions one by one.

好的,從這裏開始我們將更加深入了。下面我們一一介紹一些最常用的函數。

Instantiating GameObject / Spawning Actor  實例化一個物體

In Unity, we use the Instantiate function to create new instances of objects.

This function takes any UnityEngine.Object type (GameObject, MonoBehaviour, etc.), and makes a copy of it.

Unity中使用Instantiate ()函數實例化對象,如下:

  1. public GameObject EnemyPrefab;public Vector3 SpawnPosition;public Quaternion SpawnRotation;void Start(){    GameObject NewGO = (GameObject)Instantiate(EnemyPrefab, SpawnPosition, SpawnRotation);    NewGO.name = "MyNewGameObject";}  

In UE4, there are a couple different functions to instantiate objects, depending on your needs. NewObject is used for creating new UObject types, and SpawnActor is used for spawning AActor types.

First we will briefly talk about UObjects and NewObject. Subclassing UObject in Unreal is much like subclassing ScriptableObject in Unity. They are useful for gameplay classes that don't need to spawn into the world or have attached components like Actors do.

在UE4中,有很多不同的函數來實例化物體,需要根據你的需求來決定用哪一個。NewObject()函數是用來創建UObject類型的物體,SpawnActor()函數是用來創建AActor類型的物體。首先我們簡單的談一下UO不UObject類型和NewObject()函數。子類UObject非常像Unity中的腳本化對象類ScriptableObject(這對於只是爲了存儲數據的資源是很有用的),他們對於一些不需要再世界中實例化或者不像Actor一樣需要添加組件的物體來說非常有用。

In Unity, if you created your own subclass of ScriptableObject, you may instantiate it like this:

Unity中這樣寫:

  1. MyScriptableObjectNewSO=ScriptableObject.CreateInstance<MyScriptableObject>();  

And in Unreal, If you created your own UObject derived type, you may instantiate it like this:

UE4中,這樣寫:

  1. UMyObject*NewObj=NewObject<UMyObject>();  

So what about Actors? Actors are spawned using the SpawnActor method on a World (UWorld in C++) object. How do you get the World object? Some UObjects provide a GetWorld method for you, as an example, all Actors do.

You'll notice instead of passing in another Actor, we pass in the "class" of the Actor we want to spawn. In our example the class can be any subclass of AMyEnemy.

But what if you want to make a "copy" of another object, like what Instantiate allows you to do?

The NewObject and SpawnActor functions can also be given a "template" object to work with. Unreal will make a copy of that object, instead of making one "from scratch(從頭開始)". This will copy over all of its UPROPERTYs and components.

那對於Actor類型的物體如何實例化呢?Actors物體是通過使用一個UWorld類型的World物體上的SpawnActor()函數來實例化的。(也就是說如果我們想實例化一個Actor物體,首先要得到對應的UWrold類型的World物體)。那又如何得到這個World物體呢?一些UObject提供了GetWorld()函數,比如所有的Actors類就可以給你提供這個函數。觀察下面的函數,我們發現,我們需要傳遞進來的第一個參數是我們想要實例化的Actor的類,而不是Actor本身。在我們的實例中,這個類可以使AMyEnemy的任何子類。

但是如果我想複製一個物體,我該使用哪一種盛麗華的函數呢?NewObject()函數和SpawnActor()函數都個可以提供一個“template(模板)”物體來使用。虛幻引擎將會從這個物體來複制,而不是從頭開始實例化對象,這樣做將會把他的所有的UPROPERTYs(屬性特性)和組件拷貝到。

  1. AMyActor* CreateCloneOfMyActor(AMyActor* ExistingActor, FVector SpawnLocation, FRotator SpawnRotation){    UWorld* World = ExistingActor->GetWorld();    FActorSpawnParameters SpawnParams;    SpawnParams.Template = ExistingActor;    World->SpawnActor<AMyActor>(ExistingActor->GetClass(), SpawnLocation, SpawnRotation, SpawnParams);}  

You might be wondering what "from scratch" means in this context. Each object class you create has a default template that contain default values for its properties and components. If you don't override these properties and don't provide your own template, Unreal will use these default values to construct your object. To help illustrate this, let's first look at a MonoBehaviour for example:

你也許對上面提到的“從頭開始”不是很瞭解。其實,你創建的每一個物體的類都有一個默認的模板,它包含了物體屬性和組件的默認的值,如果你不重寫這些特性,不提供你的模板,虛幻引擎將使用默認的值來構造你的物體。爲了更好的理解這些內容,我們首先來看看Unity中的MonoBehavior是怎麼做的。

  1. public class MyComponent : MonoBehaviour{    public int MyIntProp = 42;    public SphereCollider MyCollisionComp = null;    void Start()    {        // Create the collision component if we don't already have one        if (MyCollisionComp == null)        {            MyCollisionComp = gameObject.AddComponent<SphereCollider>();            MyCollisionComp.center = Vector3.zero;            MyCollisionComp.radius = 20.0f;        }    }}  

In the above example we have an int property that defaults to 42, and a SphereCollider component that defaults to a radius of 20.

We can achieve the same thing in Unreal using the object's constructor.

在上面的例子中,我們有一個整形的參數默認值爲42,並且生成了一個球形碰撞器,它默認的半徑是20.我們可以在UE中,使用物體的構造函數來實現相同的功能。

  1. UCLASS()class AMyActor : public AActor{    GENERATED_BODY()    UPROPERTY()    int32 MyIntProp;    UPROPERTY()    USphereComponent* MyCollisionComp;    AMyActor()    {        MyIntProp = 42;        MyCollisionComp = CreateDefaultSubobject<USphereComponent>(FName(TEXT("CollisionComponent"));        MyCollisionComp->RelativeLocation = FVector::ZeroVector;        MyCollisionComp->SphereRadius = 20.0f;    }};  

In the constructor of AMyActor we have set the default property values for the class. Note the use of the CreateDefaultSubobject function. We can use it to create components and assign default properties to them. All the subobjects we create using this function act as a default template, so we can modify them in a subclass or Blueprint.在AMyActor的構造函數中,我們給這個類設置了默認的參數值,要記住使用CreateDefaultSubobject()函數。我們可以使用這個函數來創建組件並且爲其制定默認的參數。我們使用這個函數創建的所有子物體實際上就是一個默認的模板,因此我們可以在一個子類中或者藍圖中修改他們。

Casting from one Type to Another 類型轉換

In this case we get a component we know we have, then cast it to a specific type and conditionally do something.

就是根據已有的組件轉換成另一種類型來有條件的處理一些事情。

Unity C#:

  1. Collider collider = gameObject.GetComponent<Collider>;SphereCollider sphereCollider = collider as SphereCollider;if (sphereCollider != null){        // ...}  
  1. UE4 C++:UPrimitiveComponent* Primitive = MyActor->GetComponentByClass(UPrimitiveComponent::StaticClass());USphereComponent* SphereCollider = Cast<USphereComponent>(Primitive);if (SphereCollider != nullptr){        // ...}  

Destroying GameObject / Actor  銷燬物體

ity C++ Blueprint
Destroy(MyGameObject);
MyActor->Destroy();


Destroying GameObject / Actor (With 1 Second Delay)  1秒延遲銷燬物體

Unity C++ Blueprint
Destroy(MyGameObject,1);
MyActor->SetLifeSpan(1);



Disabling GameObjects / Actors  使物體處於不激活狀態

Unity C++ Blueprint
MyGameObject.SetActive(false);
// Hides visible componentsMyActor->SetActorHiddenInGame(true);// Disables collision componentsMyActor->SetActorEnableCollision(false);// Stops the Actor from tickingMyActor->SetActorTickEnabled(false);


Accessing the GameObject / Actor from Component 通過組件訪問物體

Unity C++ Blueprint
GameObjectParentGO=MyComponent.gameObject;
AActor*ParentActor=MyComponent->GetOwner();



Accessing a Component from the GameObject / Actor  通過物體訪問組件

Unity:
  1. MyComponentMyComp= gameObject.GetComponent<MyComponent>();  
C++
  1. UMyComponent*MyComp=Cast<UMyComponent>(MyActor->GetComponentByClass(UMyComponent::StaticClass()));  
Blueprint

Finding GameObjects / Actors  查找物體

  1. // Find GameObject by nameGameObject MyGO = GameObject.Find("MyNamedGameObject");// Find Objects by typeMyComponent[] Components = Object.FindObjectsOfType(typeof(MyComponent)) as MyComponent[];foreach (MyComponent Component in Components){        // ...}// Find GameObjects by tagGameObject[] GameObjects = GameObject.FindGameObjectsWithTag("MyTag");foreach (GameObject GO in GameObjects){        // ...}// Find Actor by name (also works on UObjects)AActor* MyActor = FindObject<AActor>(nullptr, TEXT("MyNamedActor"));// Find Actors by type (needs a UWorld object)for (TActorIterator<AMyActor> It(GetWorld()); It; ++It){        AMyActor* MyActor = *It;        // ...}  

  1. // Find UObjects by typefor (TObjectIterator<UMyObject> It; It; ++it){    UMyObject* MyObject = *It;    // ...}// Find Actors by tag (also works on ActorComponents, use TObjectIterator instead)for (TActorIterator<AActor> It(GetWorld()); It; ++It){    AActor* Actor = *It;    if (Actor->ActorHasTag(FName(TEXT("Mytag"))))    {        // ...    }}  

Adding tags to GameObjects / Actors  給物體添加標籤

  1. MyGameObject.tag = "MyTag";// Actors can have multiple tagsMyActor.Tags.AddUnique(TEXT("MyTag"));  

Adding tags to MonoBehaviours / ActorComponents  給組件添加標籤

  1. // This changes the tag on the GameObject it is attached toMyComponent.tag = "MyTag";// Components have their own array of tagsMyComponent.ComponentTags.AddUnique(TEXT("MyTag"));  

Comparing tags on GameObjects / Actors and MonoBehaviours / ActorComponents 使用物體和組件的標籤

  1. if (MyGameObject.CompareTag("MyTag")){    // ...}// Checks the tag on the GameObject it is attached toif (MyComponent.CompareTag("MyTag")){    // ...}// Checks if an Actor has this tagif (MyActor->ActorHasTag(FName(TEXT("MyTag")))){    // ...}  



  1. // Checks if an ActorComponent has this tagif (MyComponent->ComponentHasTag(FName(TEXT("MyTag")))){    // ...}  


Physics: RigidBody vs. Primitive Component  物理部分:RigidBody 對比 Primitive 組件

In Unity to give any GameObject physics characteristics(特性) you first give it a RigidBody component. In Unreal any PrimitiveComponent (UPrimitiveComponent in C++) can be a physical object. Some common Primitive Components are ShapeComponents (Capsule, Sphere, Box), StaticMeshComponent, and SkeletalMeshComponent.在Unity中,我們需要首先給物體一個RigidBody組件纔可以給他物理的特性。在虛幻引擎中,一個 Primitive組件可以當成是一個物理的物體。一些常用的 Primitive組件有形狀組件(膠囊,球體,立方體),靜態網格組件和骨骼網格組件。

Unlike Unity which separates the responsibilities of collision and visualizations into separate components. Unreal combines the concepts of the potentially physical and the potentially visible into PrimitiveComponent. Any component that would have any geometry(集合) in the world, that could either be rendered or interacted(相互作用) with physically sub-classes from PrimitiveComponent.

和Unity把物理碰撞和可視化的調節分開不同,虛幻引擎把可能的物理和可視化組合在PrimitiveComponent組件中。任何一個組件都在世界中擁有集合屬性,他們可以被渲染出來也可以和擁有PrimitiveComponent組件的物體相互作用。

Layers vs Channels  Unity中的Layers和UE4中的Channels

In Unity, they are called "Layers". UE4 uses Collision Channels, and they work in a similar way. You can read up on them here.

他們二者很相似,你可以在這裏 here讀它們。

RayCast vs RayTrace  光線投射

Unity C#:

  1. GameObject FindGOCameraIsLookingAt(){    Vector3 Start = Camera.main.transform.position;    Vector3 Direction = Camera.main.transform.forward;    float Distance = 100.0f;    int LayerBitMask = 1 << LayerMask.NameToLayer("Pawn");    RaycastHit Hit;    bool bHit = Physics.Raycast(Start, Direction, out Hit, Distance, LayerBitMask);    if (bHit)    {        return Hit.collider.gameObject;    }    return null;}  
C++
  1. APawn* AMyPlayerController::FindPawnCameraIsLookingAt(){    // You can use this to customize various properties about the trace    FCollisionQueryParams Params;    // Ignore the player's pawn    Params.AddIgnoredActor(GetPawn());    // The hit result gets populated by the line trace    FHitResult Hit;    // Raycast out from the camera, only collide with pawns (they are on the ECC_Pawn collision channel)    FVector Start = PlayerCameraManager->GetCameraLocation();    FVector End = Start + (PlayerCameraManager->GetCameraRotation().Vector() * 1000.0f);    bool bHit = GetWorld()->LineTraceSingle(Hit, Start, End, ECC_Pawn, Params);    if (bHit)    {        // Hit.Actor contains a weak pointer to the Actor that the trace hit        return Cast<APawn>(Hit.Actor.Get());    }    return nullptr;}  
UE4 Blueprint:

Triggers 觸發器

Unity C#:

  1. public class MyComponent : MonoBehaviour{    void Start()    {        collider.isTrigger = true;    }    void OnTriggerEnter(Collider Other)    {        // ...    }    void OnTriggerExit(Collider Other)    {        // ...    }}  
UE4 C++:
  1. UCLASS()class AMyActor : public AActor{    GENERATED_BODY()    // My trigger component    UPROPERTY()    UPrimitiveComponent* Trigger;    AMyActor()    {        Trigger = CreateDefaultSubobject<USphereComponent>(TEXT("TriggerCollider"));        // Both colliders need to have this set to true for events to fire        Trigger.bGenerateOverlapEvents = true;        // Set the collision mode for the collider        // This mode will only enable the collider for raycasts, sweeps, and overlaps        Trigger.SetCollisionEnabled(ECollisionEnabled::QueryOnly);    }    void BeginPlay()    {        // Register to find out when an overlap occurs        OnActorBeginOverlap.AddDynamic(this, &AMyActor::OnTriggerEnter);        OnActorEndOverlap.AddDynamic(this, &AMyActor::OnTriggerExit);        Super::BeginPlay();    }    void EndPlay(const EEndPlayReason::Type EndPlayReason)    {        OnActorBeginOverlap.RemoveDynamic(this, &AMyActor::OnTriggerEnter);        OnActorEndOverlap.RemoveDynamic(this, &AMyActor::OnTriggerExit);        Super:EndPlay(EndPlayReason);    }    UFUNCTION()    void OnTriggerEnter(AActor* Other);    UFUNCTION()    void OnTriggerExit(AActor* Other);};  
UE4 Blueprint:

更多碰撞觸發信息,參閱 here.

Kinematic Rigidbodies 運動學

Unity C#:

  1. public class MyComponent : MonoBehaviour{    void Start()    {        rigidbody.isKinimatic = true;        rigidbody.velocity = transform.forward * 10.0f;    }}  

In UE4, The collision component and rigidbody component are one. The base class for this is UPrimitiveComponent, which has many subclasses (USphereComponent, UCapsuleComponent, etc.) to suit your needs.

在UE4中,碰撞組件和剛體組件是一個東西。他們的父類是UPrimitiveComponent,他又很多子類來滿足你的需求,比如USphereComponent,UCapsuleComponent等等。

UE4 C++:

  1. UCLASS()class AMyActor : public AActor{    GENERATED_BODY()    UPROPERTY()    UPrimitiveComponent* PhysicalComp;    AMyActor()    {        PhysicalComp = CreateDefaultSubobject<USphereComponent>(TEXT("CollisionAndPhysics"));        PhysicalComp->SetSimulatePhysics(false);        PhysicalComp->SetPhysicsLinearVelocity(GetActorRotation().Vector() * 100.0f);    }};  

Input events  輸入事件

Unity C#:

  1. public class MyPlayerController : MonoBehaviour{    void Update()    {        if (Input.GetButtonDown("Fire"))        {            // ...        }        float Horiz = Input.GetAxis("Horizontal");        float Vert = Input.GetAxis("Vertical");        // ...    }}  
UE4 C++
  1. UCLASS()class AMyPlayerController : public APlayerController{    GENERATED_BODY()    void SetupInputComponent()    {        Super::SetupInputComponent();        InputComponent->BindAction("Fire", IE_Pressed, this, &AMyPlayerController::HandleFireInputEvent);        InputComponent->BindAxis("Horizontal"this, &AMyPlayerController::HandleHorizontalAxisInputEvent);        InputComponent->BindAxis("Vertical"this, &AMyPlayerController::HandleVerticalAxisInputEvent);    }    void HandleFireInputEvent();    void HandleHorizontalAxisInputEvent(float Value);    void HandleVerticalAxisInputEvent(float Value);};  
UE4 Blueprint:

This is what your input properties in your Project Settings might look like:

在你的項目設置中可以設置輸入的參數。


You can read more about how to setup input here.在這裏here閱讀更多輸入的信息。

FAQ 常見問題

How do I load my last project automatically? 我怎麼才能自動加載我上一次的工程呢?

If you are used to Unity automatically loading the last project you were working on, the same is possible in UE4. To enable, check "Always load last project on Startup" when opening a project. You can also toggle the setting at any time from the main Edit menu under Edit?Editor Preferences? Loading and Saving?Startup. 

在UE4中,打開一個工程的時候選中“Always load last project on Startup”選項。

Where do I set Input Bindings for my game? 我在什麼地方設置輸入的綁定信息?

In Unity you're used to using the Input Manager settings for Project to setup default bindings. In UE4 it works similarly. You'll open your Project Settings then select the Input category. There, you can add various buttons (actions) and analog controls (axes). Give each control a name and default binding. Then, you can get callbacks to your game's Pawn when the input events are triggered. Check out the Input documentation pagefor the details.

How do I change the starting scene of my project? 我怎麼才能改變啓動場景?

You can change the startup map of your project from the project settings tab. From the main menu choose Edit?Project Settings->Maps & Modes to change the starting map.

Edit?Project Settings->Maps & Modes這裏既可以設置

How do I run my game? 我怎麼才能運行我的遊戲?

The easiest way to run your game is to click the "Play" button on the the main editor toolbar, which will run the game right inside the editor's process. If you want to run it as a standalone application, click the dropdown arrow next to "Play" and choose "Standalone Game". Finally, if you want to run on a mobile device or in a web browser, you'll use the "Launch" button on the toolbar (after installing any prerequisites that are needed for that platform.)

What units are these? 應該使用什麼樣的單位?

In Unity the primary unit of measurement is one meter. In UE4 the primary unit of measurement is one centimeter.UE4中最基本的單位是釐米。

So if you move something 1 unit (meter) in unity that is equivalent to moving something 100 units (centimeters) in UE4.

If you want to move something 2 Feet in Unity that would be 0.61units (meter) and in UE4 is 61 units (centimeters).

What is with this coordinate system? Which way is up?  座標系統怎麼使用?

Both Unity and UE4 use a left-handed coordinate system, but the axes are swapped around. In UE4, positive X is "forward", positive Y is "right" and positive Z is "up". This can't be changed, so you'll have to get used to it.UE4中,x軸:前;Y:右,Z:上。

How do I see Log Output from my game? 怎麼看調試輸出信息?

In the UE4 editor you can open the "Output Log" from the "Window -> Developer Tools" menu. You can also run your game with the "-log" command-line parameter to summon a dedicated log window alongside your game, which is really useful!

UE4編輯器中:Window -> Developer Tools

Speaking of Log Output, where is my Debug.Log? 我的Debug.Log()函數去哪裏了?

Logging in UE4 is highly customizable. Read up on how to log messages here.

How do I throw exceptions? 我怎麼才能拋出異常錯誤?

In Unity you're used to throwing exceptions when things go wrong. UE4 doesn't use exception handling. Instead use the 'check()' function to trigger a critical assertion error. You can pass in an error message. If you want to report an error but not halt the program, use 'ensure()' instead. This will log an error with a full call stack, but program execution will continue. If you had a debugger attached, both functions will break into the debugger.

UE4中沒有這樣的機制,而是使用check()函數。

Where is the .NET Framework? .NetFramework在哪裏?

Unlike Unity, UE4 does not use the .NET framework. UE4 has it's own set of Container classes and libraries. Common container comparisons:

.Net Framework UE4
String FStringFText
List TArray
Dictionary TMap
HashSet TSet

You can learn more about other UE4 containers here.

Does Unreal automatically reload code changes? 虛幻引擎能熱更新代碼嗎?

Yes! You can leave the editor open while you write code. Simply kick off a compile from Visual Studio after you've finished editing code, and the editor will "hot reload" your changes automatically. You can also click the Compile button on the editor's main toolbar. That can be useful when you have the Visual Studio debugger attached.

當然可以。

Where to go from here 從這裏繼續深入研究

Thanks for reading the guide! This was created for the Unreal community with the help of Unreal developers everywhere, and we very much appreciate any feedback and corrections you can offer. We'll try to keep improving this document as we learn more about what's most helpful when transitioning to UE4!

We have many additional UE4 learning resources available!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章