Version: Unreal 4.26

问题

  • 为啥UE编辑器会有EPlayNetMode有三种让你选择。
  • 为啥描述World 的ENetMode 会有4种,而不只是(Client/Server 2种)。
  • 为何Actor 会有Role的概念。

EPlayNetMode

UENUM()
enum EPlayNetMode
{
/** A non-networked game will be started. This can be used in combination with bLaunchSeparateServer to test menu -> server flow in your game. */
PIE_Standalone UMETA(DisplayName="Play Offline"),
/** The editor will act as both a Server and a Client. Additional instances may be opened beyond that depending on the number of clients. */
PIE_ListenServer UMETA(DisplayName="Play As Listen Server"),
/** The editor will act as a Client. A server will be started for you behind the scenes to connect to. */
PIE_Client UMETA(DisplayName="Play As Client"),
};
  • PIE_Standalone

    单机玩法,本地直接有一个所谓的服务器和一个或多个玩家。因此尤其注意相关网络请求rpc,值复制等都是同步执行的。

    应用:一般游戏的训练场啊,游戏大厅,新手引导关卡。不需要跟其他玩家交互的场景。

  • PIE_Client

    一般用于多人在线联网战斗局内,比如吃鸡游戏那种开房间成功后进入局内战斗,就是所谓的战斗局内,用这个比较多。

    应用:比如吃鸡游戏的战斗场景(与其他联网玩家战斗交互)。

  • PIE_ListenServer

    一般用于开发局域网游戏。

    应用:无(我没用过,现在好像没有开发局域网游戏的了吧)。


综上:就是方便为了给UE 编辑器用户开发测试使用。

ENetMode


//* The network mode the game is currently running.*/
enum ENetMode
{
/** Standalone: a game without networking, with one or more local players. Still considered a server because it has all server functionality. */
NM_Standalone, /** Dedicated server: server with no local players. */
NM_DedicatedServer, /** Listen server: a server that also has a local player who is hosting the game, available to other players on the network. */
NM_ListenServer, /**
* Network client: client connected to a remote server.
* Note that every mode less than this value is a kind of server, so checking NetMode < NM_Client is always some variety of server.
*/
NM_Client,
};
  • NM_Standalone

    如果你开启的是PIE_Standalone,所谓的客户端和服务器的World()->GetNetMode()都会只是NM_Standalone.

  • NM_DedicatedServer

    如果你开启的是PIE_Client,服务器上的World()->GetNetMode()才会是NM_DedicatedServer.

  • NM_Client

    如果你开启的是PIE_Client,客户端上的World()->GetNetMode()才会是NM_Client.

  • NM_ListenServer

    如果你开启的是PIE_Standalone,所谓的客户端和服务器的World()->NetMode 都会只是PIE_Standalone.

ENetRole

class ENGINE_API AActor : public UObject
{
/** Describes how much control the local machine has over the actor. */
UPROPERTY(Replicated)
TEnumAsByte<enum ENetRole> Role; /** Returns how much control the remote machine has over this actor. */
UPROPERTY(Replicated, Transient)
TEnumAsByte<enum ENetRole> RemoteRole;
} /** The network role of an actor on a local/remote network context */
enum ENetRole
{
/** No role at all. */
ROLE_None,
/** Locally simulated proxy of this actor. */
ROLE_SimulatedProxy,
/** Locally autonomous proxy of this actor. */
ROLE_AutonomousProxy,
/** Authoritative control over the actor. */
ROLE_Authority,
};

前面的ENetMode针对的是世界才能调用的,这个ENetRole是Actor才能调用的。你需要了解Actor是作为UE 可以同步的最小单元。

主要是Actor的Role和RemoteRole,大概描述的是这个Actor本地的控制性和远端的控制性。还有一点需要申明,只能是服务器复制Actor到客户端,客户端不会复制Actor到服务器。

服务器创建Actor

  • 不复制到客户端
  • Role:ROLE_Authority
  • RemoteRole:ROLE_None
  • 复制到客户端
  • Role:ROLE_Authority
  • RemoteRole:ROLE_SimulatedProxy 或 ROLE_AutonomousProxy

客户端创建Actor

  • Role:ROLE_Authority
  • RemoteRole:ROLE_None

应用:

从服务器复制一个Actor到ABCD四个客户端,那么我可以在这个Actor 的BeginPlay里判断打印log。

this->GetLocalRole() == ROLE_AutonomousProxy 就是A客户端,只打印一次。
this->GetLocalRole() == ROLE_Authority 就是服务器,只打印一次。
this->GetLocalRole() == ROLE_SimulatedProxy 就是BCD客户端,打印三次。

通俗的说:目的是为了描述这个Actor是服务器生成的;还是客户端生成的;还是服务器生成复制到客户端的;还是服务器复制到客户端,这个客户端是本地玩家还是非本地玩家。

本地玩家的,还是非本地玩家的,这是个相对的概念,客户端是我,就是本地玩家,专业术语是主控端(是我),还是模拟端。。

参考

Unreal NetMode&NetRole 解析的更多相关文章

  1. Unreal 输入系统 解析

    前言 输入系统,输入某个键,响应到GamePlay层做对应的事.例如 点击鼠标,前进还是开枪之类,是如何响应的.这里只说应用层逻辑,硬件层逻辑不讲述. 详解 1.问题来源 先看下面一个例子:跳跃的事件 ...

  2. 一些VR延迟优化方法

    http://m.blog.csdn.net/article/details?id=50667507 VR中的”延迟”, 特指”Motion-To-Photon Latency”, 指的是从用户运动开 ...

  3. 《Note --- Unreal --- MemPro (CONTINUE... ...)》

    Mem pro 是一个主要集成内存泄露检测的工具,其具有自身的源码和GUI,在GUI中利用"Launch" button进行加载自己待检测的application,目前支持的平台为 ...

  4. 《Note --- Unreal 4 --- behavior tree》

    Web: https://docs.unrealengine.com/latest/INT/Engine/AI/BehaviorTrees/index.html Test project: D:\En ...

  5. C++程序员如何入门Unreal Engine 4

    摘要: 一位程序员网友小保哥分享自己的UE4快速上手过程,只是笔记,52VR做了一点更加适合阅读的修改,整理给大家. 首先,本文只是针对有比较熟练C++技能的程序员,他可以没有任何图形学或游戏引擎方面 ...

  6. 虚幻4外包团队-推荐非常全面的的Unreal教程

    <Unreal SDK 游戏开发从入门到精通(UnrealScript语法.UI Scene界面.UDK独立开发游戏)> 课程讲师:Shark  课程分类:.net 适合人群:初级 课时数 ...

  7. 游戏音频技术备忘 (五)Wwise Unreal Engine 集成代码浅析 二

    AkAmbientSound类的实现 Unreal Engine提供了一个基本对象的构造器ObjectInitializer,一般来说用户创建的类总是拥有很多变量,因此 AkAmbientSound  ...

  8. (原、整)Unreal源码 CoreUbject- Uobject

    (原.整) Unreal源码 CoreUbject- Uobject 类别                    [随笔分类]Unreal源码搬山 @author:白袍小道 随缘那啥 这里还是属于UE ...

  9. (原)Unreal-GamePlayer-Actor解析(1)

    (原)Unreal-GamePlayer-Actor解析(1) @author 白袍小道 前言 属于Unreal的 GamePlay 框架中Actor细节部分.主要关于Actor及其相关部件和实体的几 ...

随机推荐

  1. docker可视化

    可视化第一种方式 Portainer(不是最佳选择但先用这个) docker run -d -p 8088:9000 \ #docker run 启动:通过内网9000端口,外网8088端口:rest ...

  2. 在Apache Cassandra数据库软件中报告高严重性RCE安全漏洞

    研究人员披露了ApacheCassandra一个现已修补的高严重性安全漏洞的细节,如果这个漏洞得不到解决,可能会被滥用来获取受影响安装的远程代码执行(RCE). DevOps公司JFrog的安全研究员 ...

  3. Netty整合STOMP

    1.STOMP协议简介 常用的WebSocket协议定义了两种传输信息类型:文本信息和二进制信息.类型虽然被确定,但是他们的传输体是没有规定的,也就是说传输体可以自定义成什么样的数据格式都行,只要客户 ...

  4. KingbaseES R6 集群修改ssh端口执行sys_backup.sh备份案例

    数据库环境:** test=# select version(); version ---------------------------------------------------------- ...

  5. Springboot多属性文件配置

    Springboot 多属性文件配置 配置文件后缀有两种: .properties和.yml 要完成多属性配置需要自定义PropertySourcesPlaceholderConfigurer 这个B ...

  6. C语言可以在执行语句中间定义变量吗?

    C语言可以在执行语句中间定义变量吗? 例如:for(int i=0; i<5; i++){                                                     ...

  7. WinUI 3 踩坑记:第一个窗口

    本文是 WinUI 3 踩坑记 的一部分,该系列发布于 GitHub@Scighost/WinUI3Keng,文中的代码也在此仓库中,若内容出现冲突以 GitHub 上的为准. WinUI 3 应用的 ...

  8. java script 日常学习 正则表达式

    <!DOCTYPE html><html><head> <title>函数的运用</title> <meta charset=&quo ...

  9. stm32fxx_hal_i2c.c解读之HAL_I2C_Mem_Write

    HAL_I2C_Mem_Write()函数位于stm32fxx_hal_i2c.c文件的2432行,源代码对该函数的解释如下图 HAL_StatusTypeDef HAL_I2C_Mem_Write( ...

  10. Redisson多策略注解限流

    限流:使用Redisson的RRateLimiter进行限流 多策略:map+函数式接口优化if判断 自定义注解 /** * aop限流注解 */ @Target({ElementType.METHO ...