UE4的World
1 类图
首先看类关系图
2 World
在前面随笔中提到世界是由一个或多个关卡组成。在这里给出部分world的源码以进一步做理解和探究
2.1 World介绍
World代码过长,只给出部分代码。
/**
* The World is the top level object representing a map or a sandbox in which Actors and Components will exist and be rendered.
*
* A World can be a single Persistent Level with an optional list of streaming levels that are loaded and unloaded via volumes and blueprint functions
* or it can be a collection of levels organized with a World Composition.
*
* In a standalone game, generally only a single World exists except during seamless area transitions when both a destination and current world exists.
* In the editor many Worlds exist: The level being edited, each PIE instance, each editor tool which has an interactive rendered viewport, and many more.
*
*/
UCLASS(customConstructor, config=Engine)
class ENGINE_API UWorld final : public UObject, public FNetworkNotify
{
GENERATED_UCLASS_BODY()
~UWorld();
/** Array of levels currently in this world. Not serialized to disk to avoid hard references. */
UPROPERTY(Transient)
TArray<class ULevel*> Levels;
/** The current GameMode, valid only on the server */
UPROPERTY(Transient)
class AGameModeBase* AuthorityGameMode;
/** The replicated actor which contains game state information that can be accessible to clients. Direct access is not allowed, use GetGameState<>() */
UPROPERTY(Transient)
class AGameStateBase* GameState;
/** All levels information from which our world is composed */
UPROPERTY()
class UWorldComposition* WorldComposition;
/** Physics scene for this world. */
FPhysScene* PhysicsScene;
/**
* The persistent level associated with this collection.
* The source collection and the duplicated collection will have their own instances.
*/
UPROPERTY()
class ULevel* PersistentLevel;
/** Priority sorted array of streaming levels actively being considered. */
UPROPERTY()
TArray<ULevelStreaming*> StreamingLevels;
UPROPERTY(Transient)
class UGameInstance* OwningGameInstance;
/** Pointer to the current level being edited. Level has to be in the Levels array and == PersistentLevel in the game. */
UPROPERTY(Transient)
class ULevel* CurrentLevel;
/** List of all the controllers in the world. */
TArray<TWeakObjectPtr<class AController> > ControllerList;
/** List of all the player controllers in the world. */
TArray<TWeakObjectPtr<class APlayerController> > PlayerControllerList;
/** List of all the cameras in the world that auto-activate for players. */
TArray<TWeakObjectPtr<ACameraActor> > AutoCameraActorList;
首先看源码中对World类的注释:
-
World是顶级的关卡对象,它表现为地图或者沙盒。Actor和Component存在于这个地图或者沙盒中,并且对Actor和Component渲染也是在这里完成。
-
World可以是由单个Persistent Level和一系列可选的streaming Level组成。这些streaming Level可以通过体积或者函数进行加载和卸载,或者World可以是一个由World Composition组织起来的Level集合。
-
在独立游戏中,通常只存在一个世界,除非在无缝区域转换期间同时存在目的地和当前世界。
-
在编辑器中存在许多世界:正在编辑的关卡、每个 PIE 实例、每个具有交互式渲染视口的编辑器工具等等。
一个World由一个或多个Level组成,那么自然而然地,World就需要管理这些Level,负责它们的加载和释放。在UE中,每个World支持一个PersistentLevel和多个其他Level:PersistentLevel在开始时就加载进World,Streaming Level则是后续动态加载的level。Levels保存当前World中已经加载的Level,StreamingLevels则保存整个World的Levels配置列表。PersistentLevel和CurrentLevel是快速引用。在编辑器中,CurrentLevel可以指向其他Level,在运行时CurrentLevel只能是指向PersistentLevel。
思考: World由多个Level拼接而成,由前讲述可知,每个Level都有自己的Worldsetting,那World的配置怎么进行?
World的Settings是PersistentLevel的Worldsetting为主的,但同时其他Level的Worldsetting也发挥着作用。就是需要在整个世界范围内起作用的配置选项(比如VR的WorldToMeters,KillZ,WorldGravity其他大部分都是)从PersistentLevel的Worldsetting配置中提取。而在各自Level中起作用的配置选项则从它们各自的Worldsetting中提取。
2.2 World类型
从前面的解释中,可以知道,作为一个游戏玩家,最直观的体验就是一个地图就是一个World,游戏玩家在玩游戏时在地图上进行游戏。所以,在游戏中不止有一个,比如吃鸡游戏中就有多个地图。但同时,World也不止有一种类型,看下面源码即可知UE中World类型。
/** Specifies the goal/source of a UWorld object */
namespace EWorldType
{
enum Type
{
/** An untyped world, in most cases this will be the vestigial worlds of streamed in sub-levels */
None,
/** The game world */
Game,
/** A world being edited in the editor */
Editor,
/** A Play In Editor world */
PIE,
/** A preview world for an editor tool */
EditorPreview,
/** A preview world for a game */
GamePreview,
/** A minimal RPC world for a game */
GameRPC,
/** An editor world that was loaded but not currently being edited in the level editor */
Inactive
};
UE_DEPRECATED(4.14, "EWorldType::Preview is deprecated. Please use either EWorldType::EditorPreview or EWorldType::GamePreview")
const EWorldType::Type Preview = EWorldType::EditorPreview;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2020-04-12 树