UE官网ARPG游戏学习笔记1

Posted o0MagicWoods0o

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UE官网ARPG游戏学习笔记1相关的知识,希望对你有一定的参考价值。

内容来自官网ARPG文档https://docs.unrealengine.com/4.27/en-US/Resources/SampleGames/ARPG/GameplayAbilitiesinActionRPG/

Code Overview

Most Unreal Engine 4 (UE4) projects start from one of the existing templates, or as a clone of an existing sample project.

类似于RPGTypes.h这样内部定义了一些通用的数据类型和delegate,结构上更清晰,避免循环引用。

几乎所有游戏都会先定义一个继承于APlayerController的类似RPGPlayerControllerBase的类。在ARPG中,主要处理inventory.

RPGCharacterBase.h:蓝图Character继承自的地方。

RPGGameInstanceBase.h: 适合存放global gameplay data.

RPGBlueprintLibrary.h: Exposes game-specific Blueprint functions that are not tied to a specific Actor, almost every game will need one or more of these.与具体的Actor联系不紧密的蓝图可调用函数。

RPGSaveGame.h:用于存档

RPGAssetManager.h:Subclass of the AssetManager that is used in the inventory system.

RPGInventoryInterface.h: Native interface enabling RPGCharacterBase to query RPGPlayerControllerBase about inventory without doing manual casts.

Cast在UE中似乎是一个很费的操作。

Items/RPGItem.h and Subclasses: Different inventory item types.

Abilities/RPGAbilitySystemComponent and Others: Used in the ability system as described in Gameplay Abilities in ARPG.

ActionRPGLoadingScreen Module:用来展示texture的loading screen module, 独立为一个Module是因为需要在游戏加载前就加载。

很多其他游戏会有一个Editor Module扩展编辑器。

Inventory and Asset Manager

游戏中与几个基本的类型:武器、技能、药水等都继承自URPGItem, 并且都定义在了DefaultGame.ini中

 每个基类也提供了UI支持,像是icon等。

在playercontorllerBase中有两个映射。一个是从inventory的slot到Item*的,另一个是从Item*到ItemData的。

LoadPrimaryAssets会对一类asset逐个load.之后存储在gameinstance中。LoadPrimaryAssets会使得asset一直在内存中直到Unload被调用。

实际的保存使用了 SaveGameToSlot蓝图函数,将信息存在disk上

Packaging for Release

要保证including only the content it needs

The "CookRule=AlwaysCook" section of the Primary Asset Type configuration file causes all items in your project's Content folder to be cooked into the final game。

Once we verified that the packaged game was working correctly and all of the project's content was included we then took a look at ways to reduce download and memory size

为了减少空间消耗

1.Disable any Plugins that are not being used. Doing this for ARPG reduced the overall project size by 30 MB.
2.Enabled the Exclude editor content when cooking flag that can be found in Packaging settings. Doing this will prevent the project from shipping any content in the UE4 Editor folders like /Engine/EditorMaterials.

 4. Using the Size Map tool available from the Asset Audit window 

5. Temporarily enabled the For Distribution checkmark box in Project Settings > Packaging and changing the Build Configuration from Development to Shipping to get a better idea of what the final size of ARPG would be。

Balancing Blueprint and C++

Broadly speaking, things in a game can be divided into Logic and Data

 

C++ vs Blueprints 

  • Network Replication: Replication support in Blueprints is straightforward and is designed to be used in smaller games or for unique one-off Actors. If you need tight control over replication bandwidth or timing you will need to use C++.

  • Faster Iteration: It is much quicker to modify Blueprint logic and preview inside the editor than it is to recompile the game, although hot reload can help. This is true for both mature and new systems so all "tweakable" values should be stored in assets if possible.

  • Better For Flow: It can be complicated to visualize "game flow" in C++, so it is often better to implement that in Blueprints (or in custom systems like Behavior Trees that are designed for this). Delay and async nodes make it much easier to follow flow than using C++ delegates.

  • Easier Data Usage: Because storing data inside Blueprint classes is much simpler and safer than inside C++ classes; Blueprints are suitable for classes that closely mix Data and Logic.

在DefaultEngine.ini中

[CoreRedirects]
+ClassRedirects=(OldName="BP_Item_C", NewName="/Script/ActionRPG.RPGItem", OverrideClassName="/Script/CoreUObject.Class")
+ClassRedirects=(OldName="BP_Item_Potion_C", NewName="/Script/ActionRPG.RPGPotionItem", OverrideClassName="/Script/CoreUObject.Class")
+ClassRedirects=(OldName="BP_Item_Skill_C", NewName="/Script/ActionRPG.RPGSkillItem", OverrideClassName="/Script/CoreUObject.Class")
+ClassRedirects=(OldName="BP_Item_Weapon_C", NewName="/Script/ActionRPG.RPGWeaponItem", OverrideClassName="/Script/CoreUObject.Class")

The above code block uses the Core Redirects system to convert all references to the Blueprint BP Item C to instead reference the new native class RPGItem。The OverrideClassName option is required because it needs to know that it is now a UClass instead of a UBlueprintGeneratedClass.

Performance Concerns

Broadly, the main difference is that executing each individual node in a Blueprint is slower than executing a line of C++ code, but once execution is inside a node, it's just as fast as if it had been called from C++. For example, if your Blueprint class has a few cheap top-level nodes and then calls an expensive Physics Trace function, converting that class to C++ will not improve performance significantly. But, if your Blueprint class has a lot of tight for loops or lots of nested macros that expand into hundreds of nodes, then you should think about moving that code to C++. One of the most critical performance problems will be Tick functions. Executing a Blueprint tick can be much slower than a native tick, and you should avoid tick entirely for any class that has many instances. Instead, you should use timers or delegates to have your Blueprint class only do work when it needs to.

The best way to find out if your Blueprint classes are causing performance problems is to use the Profiler Tool.

Architecture Notes

Avoid Casting to Expensive Blueprints

Avoid Cyclical Blueprint References

  • Think about Async Loading: As your game grows larger you will want to load assets on demand instead of loading everything up front when the game loads. Once you reach this point, you will need to start converting things to use Soft references or PrimaryAssetIds instead of Hard references. The AssetManager provides several functions to make it easier to async load assets and also exposes a StreamableManager that offers lower level functions.

Avoid Referencing Assets from C++ classes

(转载)(官网)UE4--Pawn

Pawn

 

技术分享图片

**Pawn**类是可由玩家或 AI 控制的所有 Actors 的基础类。Pawn 是玩家或 AI 实体在世界中的物理象征。 这不仅意味着 Pawn 决定玩家或 AI 实体的外表,而且决定其在冲突和其它物理互动方面 如何与世界交互。由于某些类型的游戏可能在游戏中没有可见的玩家网格或形象,这在某些情况下可能会令人困惑。无论如何,Pawn 仍 代表玩家或实体在游戏中的物理位置、转动等。Character 是一种特殊类型的能走动的 Pawn。

默认情况下,控制器和 Pawn 之间是一对一的关系;意思是,每个控制器在任何特定时间只控制一个 Pawn。此外,在游戏中生成的 Pawn
不被控制器自动控制。

在 Blueprints 中,使用**SetActorLocation**是增加 Pawn 派生类的运动的最佳方式。用**SetActorLocation**,你可以决定要时空转移至或迅速前往某个位置。 迅速前往时,你的 Pawn 会沿某个方向移动,如果撞到东西就会停下来。

默认 Pawn

尽管 Pawn 类只提供创建玩家或 AI 实体在世界中的物理象征的基础,但_DefaultPawn_子类附带一些额外的组件和功能。

DefaultPawn 类包含本地 DefaultPawnMovementComponent、球形 CollisionComponent 和 StaticMeshComponent。为了控制 DefaultPawnMovementComponent 以及摄像机, DefaultPawn 类中也有用来添加默认运动约束的 Boolean,且被默认设置为_true_。

DefaultPawnMovementComponent

DefaultPawnMovementComponent 的运动风格被设置为无重力飞行风格。除通常的 MovementComponent 变量外,它还包括“MaxSpeed??”、“Acceleration”和“Deceleration”浮点值。这 三个变量也可在 DefaultPawn 派生 Blueprints 中访问。

观众 Pawn

_SpectatorPawn_类是 DefaultPawn 的子类。GameMode中,可将不同的类指定为 Pawn 和 SpectatorPawn 的默认值,而该类提供非常适合 观看功能的简单框架。像 DefaultPawn 一样,尽管 StaticMeshComponent 不是由于执行“.DoNotCreateDefaultSubobject(Super::MeshComponentName)”而创建,但它有球形 CollisionComponent。 SpectatorPawn 类的运动由 SpectatorPawnMovementComponent 处理;无重力飞行行为与 DefaultPawnMovementComponent 中的相同,并添加了在必要时 处理或忽略时间膨胀的代码。

 
原文地址:https://docs.unrealengine.com/latest/CHN/Gameplay/Framework/Pawn/index.html

以上是关于UE官网ARPG游戏学习笔记1的主要内容,如果未能解决你的问题,请参考以下文章

UE4的学习路线,自己个人能够开发一个完整的游戏的学习路线。零基础。

学习unity/ue4,哪个就业好一点?

[UE4虚幻引擎教程]-003-游戏框架的基本概念:第一个玩家控制器

游戏开发主要需要啥软件?

游戏开发之UE4添加角色到场景中

学游戏开发用哪个软件最好?