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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值