ue4-Network相关-变量同步

本文详细介绍了在UE4中如何使用蓝图和C++进行网络变量的同步,包括选择属性Replication的不同选项,如None、Replicated和RepNotify,以及在C++中如何通过标记变量和重写GetLifetimeReplicatedProps方法实现同步。

ue4-Network相关-变量同步:蓝图中同步:选择变量属性 Replication 为 Replicated,有三个可选值。

None:默认值,不会同步给服务端 Replicated:同步给服务端,再同步给其他客户端 RepNotify:选择这个的时候,会 Functions 中生产一个变量 Var 对应的方法 OnRep_Var,在 Var 改变的时候会回调 服务器和所有客户端 中该Actor的这个 OnRep_Var 方法,

参考:https://docs-origin.unrealengine.com/latest/INT/Gameplay/HowTo/Networking/ReplicateVariable/Blueprints/index.html

c++中同步:

在变量中加入标记 Replicated

?

1

2

UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite, Category = AMyNetCharacter)

    int32 Cash;

重写 AActor 的 GetLifetimeReplicatedProps 方法,加入需要同步的变量 Cash

?

1

2

3

4

5

void AMyNetCharacter::GetLifetimeReplicatedProps(TArray<flifetimeproperty>& OutLifetimeProps) const

{

    Super::GetLifetimeReplicatedProps(OutLifetimeProps);

    DOREPLIFETIME(AMyNetCharacter, Cash);

}</flifetimeproperty>

在构造函数中修改成员 bReplicates 为 true

?

1

2

3

4

5

AMyNetCharacter::AMyNetCharacter()

{

    Cash = 456;

    bReplicates = true;

}

变量标记的可选值,和蓝图对应,意思差不多 NotReplicated:不会同步给服务端 Replicated:同步给服务端,在同步给其他客户端

ReplicatedUsing:选择这个的时候,需要指定一个 Var 改变时对应的 OnRep_Var(命名无特殊要求,不过还是按照蓝图生成的规则以 OnRep_ 前缀),在 Var 改变的时候会回调这个 OnRep_Var 方法。规则和 Replicated 差不多,示例如下:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

UFUNCTION(BlueprintCallable, Category = AMyNetCharacter)

    virtual void OnRep_Money();

 

void AMyNetCharacter::OnRep_Money()

{

    FString msg = FString::Printf(TEXT("--- OnRep_Money money:%d"), Money);

    GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, *msg);

}

 

    // 指定回调函数为 OnRep_Money

    UPROPERTY(ReplicatedUsing = OnRep_Money, EditAnywhere, BlueprintReadWrite, Category = AMyNetCharacter)

        int32 Money;

 

    //重写的 GetLifetimeReplicatedProps 方法中加入需要同步的变量

    DOREPLIFETIME(AMyNetCharacter, Money);

hanxu@hanxu-OptiPlex-7090:~/桌面/carla-ue4-dev$ make PythonAPI ARGS="--python-version=3.10" parse-options: 未识别的选项 "--python-version=3.10" BuildUE4Plugins.sh: Downloading STREETMAP plugin. HEAD 目前位于 260273d Correct descriptor BuildUE4Plugins.sh: StreetMap Success! Setup.sh: Generating CMake configuration files. Setup.sh: boost-1.84.0-c10 already installed. Setup.sh: rpclib-carla-callbacks-c10 already installed. Setup.sh: gtest-1.8.1-c10 already installed. Setup.sh: recast-c10 already installed. Setup.sh: Libpng already installed. Setup.sh: Xerces-c already installed. Setup.sh: Eigen already installed. Setup.sh: Sqlite already installed. Setup.sh: PROJ already installed. Setup.sh: Patchelf already installed. fatal: 不是 git 仓库(或者任何父目录):.git fatal: 不是 git 仓库(或者任何父目录):.git fatal: 不是 git 仓库(或者任何父目录):.git Setup.sh: CARLA version -dirty. Setup.sh: Success! parse-options: 未识别的选项 "--python-version=3.10" BuildLibCarla.sh: Building LibCarla "Client.Release" configuration. ninja: no work to do. [0/1] Install the project... -- Install configuration: "Client" BuildLibCarla.sh: Success! parse-options: 未识别的选项 "--python-version=3.10" BuildOSM2ODR.sh: Building OSM2ODR. -- Eclipse version is set to 3.6 (Helios). Adjust CMAKE_ECLIPSE_VERSION if this is wrong. -- CMAKE_BINARY_DIR: /home/hanxu/桌面/carla-ue4-dev/Build/libosm2dr-build -- CMAKE_SOURCE_DIR: /home/hanxu/桌面/carla-ue4-dev/Build/libosm2dr-source -- -- Platform: -- Host: Linux-6.8.0-87-generic x86_64 -- Target: Linux-6.8.0-87-generic x86_64 -- CMake: 3.22.1 -- CMake generator: Ninja -- CMake build tool: /usr/bin/ninja -- Compiler: Clang 10.0.1 -- -- Found Proj: /home/hanxu/桌面/carla-ue4-dev/Build/proj-install/lib/libproj.a -- Could NOT find X11 (missing: X11_X11_INCLUDE_PATH X11_X11_LIB) -- Enabled features: Linux-6.8.0-87-generic x86_64 Clang 10.0.1 Release Proj -- Configuring done -- Generating done -- Build files have been written to: /home/hanxu/桌面/carla-ue4-dev/Build/libosm2dr-build ninja: no work to do. [0/1] Install the project... -- Install configuration: "Release" -- Up-to-date: /home/hanxu/桌面/carla-ue4-dev/PythonAPI/carla/dependencies/lib/libosm2odr.a -- Up-to-date: /home/hanxu/桌面/carla-ue4-dev/PythonAPI/carla/dependencies/include/OSM2ODR.h /home/hanxu/UnrealEngine_4.26/Engine/Source/ThirdParty/Linux/LibCxx/include/c++/v1 /home/hanxu/UnrealEngine_4.26/Engine/Source/ThirdParty/Linux/LibCxx/lib/Linux/x86_64-unknown-linux-gnu -- Eclipse version is set to 3.6 (Helios). Adjust CMAKE_ECLIPSE_VERSION if this is wrong. -- CMAKE_BINARY_DIR: /home/hanxu/桌面/carla-ue4-dev/Build/libosm2dr-build-server -- CMAKE_SOURCE_DIR: /home/hanxu/桌面/carla-ue4-dev/Build/libosm2dr-source -- -- Platform: -- Host: Linux-6.8.0-87-generic x86_64 -- Target: Linux-6.8.0-87-generic x86_64 -- CMake: 3.22.1 -- CMake generator: Ninja -- CMake build tool: /usr/bin/ninja -- Compiler: Clang 10.0.1 -- -- Found Proj: /home/hanxu/桌面/carla-ue4-dev/Build/proj-install-server/lib/libproj.a -- Could NOT find X11 (missing: X11_X11_INCLUDE_PATH X11_X11_LIB) -- Enabled features: Linux-6.8.0-87-generic x86_64 Clang 10.0.1 Release Proj -- Configuring done -- Generating done -- Build files have been written to: /home/hanxu/桌面/carla-ue4-dev/Build/libosm2dr-build-server ninja: no work to do. [0/1] Install the project... -- Install configuration: "Release" -- Up-to-date: /home/hanxu/桌面/carla-ue4-dev/Unreal/CarlaUE4/Plugins/Carla/CarlaDependencies/lib/libosm2odr.a -- Up-to-date: /home/hanxu/桌面/carla-ue4-dev/Unreal/CarlaUE4/Plugins/Carla/CarlaDependencies/include/OSM2ODR.h -- Eclipse version is set to 3.6 (Helios). Adjust CMAKE_ECLIPSE_VERSION if this is wrong. -- CMAKE_BINARY_DIR: /home/hanxu/桌面/carla-ue4-dev/Build/libosm2dr-build-server -- CMAKE_SOURCE_DIR: /home/hanxu/桌面/carla-ue4-dev/Build/libosm2dr-source -- -- Platform: -- Host: Linux-6.8.0-87-generic x86_64 -- Target: Linux-6.8.0-87-generic x86_64 -- CMake: 3.22.1 -- CMake generator: Ninja -- CMake build tool: /usr/bin/ninja -- Compiler: Clang 10.0.1 -- -- Found Proj: /home/hanxu/桌面/carla-ue4-dev/Build/proj-install-server/lib/libproj.a -- Could NOT find X11 (missing: X11_X11_INCLUDE_PATH X11_X11_LIB) -- Enabled features: Linux-6.8.0-87-generic x86_64 Clang 10.0.1 Release Proj -- Configuring done -- Generating done -- Build files have been written to: /home/hanxu/桌面/carla-ue4-dev/Build/libosm2dr-build-server ninja: no work to do. [0/1] Install the project... -- Install configuration: "Release" -- Up-to-date: /home/hanxu/桌面/carla-ue4-dev/Unreal/CarlaUE4/Plugins/Carla/CarlaDependencies/lib/libosm2odr.a -- Up-to-date: /home/hanxu/桌面/carla-ue4-dev/Unreal/CarlaUE4/Plugins/Carla/CarlaDependencies/include/OSM2ODR.h BuildOSM2ODR.sh: OSM2ODR Success! BuildPythonAPI.sh: Building Python API wheel for Python 3.10. * Creating venv isolated environment... * Installing packages in isolated environment... (distro, setuptools, wheel) Collecting distro Downloading distro-1.9.0-py3-none-any.whl (20 kB) Collecting wheel Downloading wheel-0.45.1-py3-none-any.whl (72 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 72.5/72.5 KB 9.9 kB/s eta 0:00:00 Collecting setuptools Downloading setuptools-80.9.0-py3-none-any.whl (1.2 MB) ━━━━━━━━━━━━━━━╸ 0.5/1.2 MB 8.7 kB/s eta 0:01:24 ERROR: Exception: Traceback (most recent call last): File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_vendor/urllib3/response.py", line 438, in _error_catcher yield File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_vendor/urllib3/response.py", line 519, in read data = self._fp.read(amt) if not fp_closed else b"" File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_vendor/cachecontrol/filewrapper.py", line 90, in read data = self.__fp.read(amt) File "/usr/lib/python3.10/http/client.py", line 466, in read s = self.fp.read(amt) File "/usr/lib/python3.10/socket.py", line 705, in readinto return self._sock.recv_into(b) File "/usr/lib/python3.10/ssl.py", line 1303, in recv_into return self.read(nbytes, buffer) File "/usr/lib/python3.10/ssl.py", line 1159, in read return self._sslobj.read(len, buffer) TimeoutError: The read operation timed out During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 165, in exc_logging_wrapper status = run_func(*args) File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 205, in wrapper return func(self, options, args) File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 339, in run requirement_set = resolver.resolve( File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 94, in resolve result = self._result = resolver.resolve( File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 481, in resolve state = resolution.resolve(requirements, max_rounds=max_rounds) File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 348, in resolve self._add_to_criteria(self.state.criteria, r, parent=None) File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 172, in _add_to_criteria if not criterion.candidates: File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_vendor/resolvelib/structs.py", line 151, in __bool__ return bool(self._sequence) File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 155, in __bool__ return any(self) File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 143, in <genexpr> return (c for c in iterator if id(c) not in self._incompatible_ids) File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 47, in _iter_built candidate = func() File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 215, in _make_candidate_from_link self._link_candidate_cache[link] = LinkCandidate( File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 288, in __init__ super().__init__( File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 158, in __init__ self.dist = self._prepare() File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 227, in _prepare dist = self._prepare_distribution() File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 299, in _prepare_distribution return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True) File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 487, in prepare_linked_requirement return self._prepare_linked_requirement(req, parallel_builds) File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 532, in _prepare_linked_requirement local_file = unpack_url( File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 214, in unpack_url file = get_http_url( File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 94, in get_http_url from_path, content_type = download(link, temp_dir.path) File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_internal/network/download.py", line 146, in __call__ for chunk in chunks: File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_internal/cli/progress_bars.py", line 304, in _rich_progress_bar for chunk in iterable: File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_internal/network/utils.py", line 63, in response_chunks for chunk in response.raw.stream( File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_vendor/urllib3/response.py", line 576, in stream data = self.read(amt=amt, decode_content=decode_content) File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_vendor/urllib3/response.py", line 512, in read with self._error_catcher(): File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__ self.gen.throw(typ, value, traceback) File "/tmp/build-env-6y9nh47d/lib/python3.10/site-packages/pip/_vendor/urllib3/response.py", line 443, in _error_catcher raise ReadTimeoutError(self._pool, None, "Read timed out.") pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out. Traceback (most recent call last): File "/usr/lib/python3/dist-packages/build/__main__.py", line 372, in main built = build_call( File "/usr/lib/python3/dist-packages/build/__main__.py", line 202, in build_package out = _build(isolation, builder, outdir, distribution, config_settings, skip_dependency_check) File "/usr/lib/python3/dist-packages/build/__main__.py", line 140, in _build return _build_in_isolated_env(builder, outdir, distribution, config_settings) File "/usr/lib/python3/dist-packages/build/__main__.py", line 108, in _build_in_isolated_env env.install(builder.build_system_requires) File "/usr/lib/python3/dist-packages/build/env.py", line 211, in install _subprocess(cmd) File "/usr/lib/python3/dist-packages/build/env.py", line 81, in _subprocess raise e File "/usr/lib/python3/dist-packages/build/env.py", line 78, in _subprocess subprocess.check_output(cmd, stderr=subprocess.STDOUT) File "/usr/lib/python3.10/subprocess.py", line 421, in check_output return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, File "/usr/lib/python3.10/subprocess.py", line 526, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['/tmp/build-env-6y9nh47d/bin/python', '-Im', 'pip', 'install', '--use-pep517', '--no-warn-script-location', '-r', '/tmp/build-reqs-temjmr2u.txt']' returned non-zero exit status 2. ERROR Command '['/tmp/build-env-6y9nh47d/bin/python', '-Im', 'pip', 'install', '--use-pep517', '--no-warn-script-location', '-r', '/tmp/build-reqs-temjmr2u.txt']' returned non-zero exit status 2. make: *** [Util/BuildTools/Linux.mk:89:PythonAPI] 错误 1 hanxu@hanxu-OptiPlex-7090:~/桌面/carla-ue4-dev$ make PythonAPI BuildUE4Plugins.sh: Downloading STREETMAP plugin. HEAD 目前位于 260273d Correct descriptor BuildUE4Plugins.sh: StreetMap Success! Setup.sh: Generating CMake configuration files. Setup.sh: boost-1.84.0-c10 already installed. Setup.sh: rpclib-carla-callbacks-c10 already installed. Setup.sh: gtest-1.8.1-c10 already installed. Setup.sh: recast-c10 already installed. Setup.sh: Libpng already installed. Setup.sh: Xerces-c already installed. Setup.sh: Eigen already installed. Setup.sh: Sqlite already installed. Setup.sh: PROJ already installed. Setup.sh: Patchelf already installed. fatal: 不是 git 仓库(或者任何父目录):.git fatal: 不是 git 仓库(或者任何父目录):.git fatal: 不是 git 仓库(或者任何父目录):.git Setup.sh: CARLA version -dirty. Setup.sh: Success! BuildLibCarla.sh: Building LibCarla "Client.Release" configuration. ninja: no work to do. [0/1] Install the project... -- Install configuration: "Client" BuildLibCarla.sh: Success! BuildOSM2ODR.sh: Building OSM2ODR. -- Eclipse version is set to 3.6 (Helios). Adjust CMAKE_ECLIPSE_VERSION if this is wrong. -- CMAKE_BINARY_DIR: /home/hanxu/桌面/carla-ue4-dev/Build/libosm2dr-build -- CMAKE_SOURCE_DIR: /home/hanxu/桌面/carla-ue4-dev/Build/libosm2dr-source -- -- Platform: -- Host: Linux-6.8.0-87-generic x86_64 -- Target: Linux-6.8.0-87-generic x86_64 -- CMake: 3.22.1 -- CMake generator: Ninja -- CMake build tool: /usr/bin/ninja -- Compiler: Clang 10.0.1 -- -- Found Proj: /home/hanxu/桌面/carla-ue4-dev/Build/proj-install/lib/libproj.a -- Could NOT find X11 (missing: X11_X11_INCLUDE_PATH X11_X11_LIB) -- Enabled features: Linux-6.8.0-87-generic x86_64 Clang 10.0.1 Release Proj -- Configuring done -- Generating done -- Build files have been written to: /home/hanxu/桌面/carla-ue4-dev/Build/libosm2dr-build ninja: no work to do. [0/1] Install the project... -- Install configuration: "Release" -- Up-to-date: /home/hanxu/桌面/carla-ue4-dev/PythonAPI/carla/dependencies/lib/libosm2odr.a -- Up-to-date: /home/hanxu/桌面/carla-ue4-dev/PythonAPI/carla/dependencies/include/OSM2ODR.h /home/hanxu/UnrealEngine_4.26/Engine/Source/ThirdParty/Linux/LibCxx/include/c++/v1 /home/hanxu/UnrealEngine_4.26/Engine/Source/ThirdParty/Linux/LibCxx/lib/Linux/x86_64-unknown-linux-gnu -- Eclipse version is set to 3.6 (Helios). Adjust CMAKE_ECLIPSE_VERSION if this is wrong. -- CMAKE_BINARY_DIR: /home/hanxu/桌面/carla-ue4-dev/Build/libosm2dr-build-server -- CMAKE_SOURCE_DIR: /home/hanxu/桌面/carla-ue4-dev/Build/libosm2dr-source -- -- Platform: -- Host: Linux-6.8.0-87-generic x86_64 -- Target: Linux-6.8.0-87-generic x86_64 -- CMake: 3.22.1 -- CMake generator: Ninja -- CMake build tool: /usr/bin/ninja -- Compiler: Clang 10.0.1 -- -- Found Proj: /home/hanxu/桌面/carla-ue4-dev/Build/proj-install-server/lib/libproj.a -- Could NOT find X11 (missing: X11_X11_INCLUDE_PATH X11_X11_LIB) -- Enabled features: Linux-6.8.0-87-generic x86_64 Clang 10.0.1 Release Proj -- Configuring done -- Generating done -- Build files have been written to: /home/hanxu/桌面/carla-ue4-dev/Build/libosm2dr-build-server ninja: no work to do. [0/1] Install the project... -- Install configuration: "Release" -- Up-to-date: /home/hanxu/桌面/carla-ue4-dev/Unreal/CarlaUE4/Plugins/Carla/CarlaDependencies/lib/libosm2odr.a -- Up-to-date: /home/hanxu/桌面/carla-ue4-dev/Unreal/CarlaUE4/Plugins/Carla/CarlaDependencies/include/OSM2ODR.h -- Eclipse version is set to 3.6 (Helios). Adjust CMAKE_ECLIPSE_VERSION if this is wrong. -- CMAKE_BINARY_DIR: /home/hanxu/桌面/carla-ue4-dev/Build/libosm2dr-build-server -- CMAKE_SOURCE_DIR: /home/hanxu/桌面/carla-ue4-dev/Build/libosm2dr-source -- -- Platform: -- Host: Linux-6.8.0-87-generic x86_64 -- Target: Linux-6.8.0-87-generic x86_64 -- CMake: 3.22.1 -- CMake generator: Ninja -- CMake build tool: /usr/bin/ninja -- Compiler: Clang 10.0.1 -- -- Found Proj: /home/hanxu/桌面/carla-ue4-dev/Build/proj-install-server/lib/libproj.a -- Could NOT find X11 (missing: X11_X11_INCLUDE_PATH X11_X11_LIB) -- Enabled features: Linux-6.8.0-87-generic x86_64 Clang 10.0.1 Release Proj -- Configuring done -- Generating done -- Build files have been written to: /home/hanxu/桌面/carla-ue4-dev/Build/libosm2dr-build-server ninja: no work to do. [0/1] Install the project... -- Install configuration: "Release" -- Up-to-date: /home/hanxu/桌面/carla-ue4-dev/Unreal/CarlaUE4/Plugins/Carla/CarlaDependencies/lib/libosm2odr.a -- Up-to-date: /home/hanxu/桌面/carla-ue4-dev/Unreal/CarlaUE4/Plugins/Carla/CarlaDependencies/include/OSM2ODR.h BuildOSM2ODR.sh: OSM2ODR Success! BuildPythonAPI.sh: Building Python API wheel for Python 3. * Creating venv isolated environment... * Installing packages in isolated environment... (distro, setuptools, wheel) WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, '连接被对方重置'))': /simple/wheel/ Collecting wheel Using cached wheel-0.45.1-py3-none-any.whl (72 kB) Collecting setuptools Downloading setuptools-80.9.0-py3-none-any.whl (1.2 MB) ━━━━━━╸ 0.2/1.2 MB 18.3 kB/s eta 0:00:55 ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them. setuptools from https://files.pythonhosted.org/packages/a3/dc/17031897dae0efacfea57dfd3a82fdd2a2aeb58e0ff71b77b87e44edc772/setuptools-80.9.0-py3-none-any.whl#sha256=062d34222ad13e0cc312a4c02d73f059e86a4acbfbdea8f8f76b28c99f306922 (from -r /tmp/build-reqs-yvoes9l5.txt (line 2)): Expected sha256 062d34222ad13e0cc312a4c02d73f059e86a4acbfbdea8f8f76b28c99f306922 Got 7914852f8c529b1ae08a5182c18a1f3d3c51969f48c4acfddcd95bc2d623829c Traceback (most recent call last): File "/usr/lib/python3/dist-packages/build/__main__.py", line 372, in main built = build_call( File "/usr/lib/python3/dist-packages/build/__main__.py", line 202, in build_package out = _build(isolation, builder, outdir, distribution, config_settings, skip_dependency_check) File "/usr/lib/python3/dist-packages/build/__main__.py", line 140, in _build return _build_in_isolated_env(builder, outdir, distribution, config_settings) File "/usr/lib/python3/dist-packages/build/__main__.py", line 108, in _build_in_isolated_env env.install(builder.build_system_requires) File "/usr/lib/python3/dist-packages/build/env.py", line 211, in install _subprocess(cmd) File "/usr/lib/python3/dist-packages/build/env.py", line 81, in _subprocess raise e File "/usr/lib/python3/dist-packages/build/env.py", line 78, in _subprocess subprocess.check_output(cmd, stderr=subprocess.STDOUT) File "/usr/lib/python3.10/subprocess.py", line 421, in check_output return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, File "/usr/lib/python3.10/subprocess.py", line 526, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['/tmp/build-env-7hydqfk7/bin/python', '-Im', 'pip', 'install', '--use-pep517', '--no-warn-script-location', '-r', '/tmp/build-reqs-yvoes9l5.txt']' returned non-zero exit status 1. ERROR Command '['/tmp/build-env-7hydqfk7/bin/python', '-Im', 'pip', 'install', '--use-pep517', '--no-warn-script-location', '-r', '/tmp/build-reqs-yvoes9l5.txt']' returned non-zero exit status 1. make: *** [Util/BuildTools/Linux.mk:89:PythonAPI] 错误 1
最新发布
12-05
<think>首先,用户的问题是:“我想了解UE中帧同步和状态同步的区别及应用场景请问Unreal Engine帧同步与状态同步区别应用场景”。所以,我需要专注于解释UnrealEngine中的帧同步和状态同步的区别,以及它们的应用场景。从系统级指令:-所有行内数学表达式必须使用$...$格式。-独立公式必须使用$$...$$格式并单独成段。 -LaTeX语法正确。-使用中文回答。-生成相关问题。 -回答中引用的段落末尾自然地添加引用标识,例如[^1]。-回答结构清晰,帮助用户逐步解决问题,尽量保证回答真实可靠。 参考站内引用:-引用[1]:关于蓝图系统的网络同步,Replicated变量和函数。 -引用[2]:帧同步和状态同步技术,混合精度同步-引用[3]:实现网络同步,使用Replicated变量-引用[4]: Unreal Engine项目管理与云存储。 -引用[5]:客户端-服务器架构。 用户的问题是关于帧同步和状态同步的区别和应用场景,所以我应该主要引用[2],因为它直接提到了帧同步和状态同步技术。其他引用如[1]和[3]是关于网络同步的实现细节,[4]和[5]是相关的但可能不那么直接。关键点:-同步(FrameSynchronization):在游戏中,所有客户端运行相同的逻辑帧,输入被同步,确保每个帧的计算一致。-状态同步(StateSynchronization):服务器发送游戏状态给客户端,客户端根据状态更新显示。区别:-同步同步输入,让每个客户端自己计算状态。适用于需要高一致性的游戏,如RTS或格斗游戏。 -状态同步同步状态,客户端直接接收状态变化。适用于FPS或MMO,其中状态变化频繁。应用场景: -同步:当游戏逻辑需要完全一致时,带宽要求较低,但延迟敏感。-状态同步:当状态变化复杂时,带宽要求较高,但更灵活。在Unreal Engine中,蓝图系统支持状态同步通过Replicated变量和函数(引用[1]和[3])。帧同步可能需要自定义实现或使用特定插件。 回答结构:1.**介绍帧同步和状态同步**:简要定义两者。 2. **详细区别**:解释核心机制、优缺点。 3. **应用场景**:给出具体例子。4.**在UnrealEngine中的实现**:结合引用,说明如何实现。 5. **生成相关问题**:在结尾添加相关问题。 使用引用: -自然地添加引用标识,例如在解释时提到“如引用[2]所述”。数学表达式:如果涉及计算,使用LaTeX格式。但用户问题可能不需要数学,除非讨论同步算法。例如,如果提到时间同步,可以用$t$表示时间。语言:中文回答。 相关问题:生成3-5个相关问题,基于主题。 完整回答框架: -开头:直接回答问题。-主体:-同步解释。-状态同步解释。-区别对比。-应用场景。- UE实现参考。 -结尾:相关问题。</think>### Unreal Engine 帧同步与状态同步的区别及应用场景 在Unreal Engine(UE)中,帧同步和状态同步是两种常见的网络同步技术,用于确保多人游戏中所有玩家看到一致的游戏状态。它们各有优缺点,适用于不同的场景。下面我将逐步解释它们的核心区别,并结合UE的实现细节和应用场景进行分析。回答基于UE的官方文档和常见实践,确保真实可靠。 #### 1. **帧同步(Frame Synchronization)** - **核心机制**:帧同步依赖于同步所有客户端的输入(如按键操作),而不是直接同步游戏状态。每个客户端运行相同的逻辑帧,并根据相同的输入序列独立计算游戏状态。这确保了所有客户端在每一帧的计算结果完全一致。例如,在每一帧$t$,所有客户端接收相同的输入数据$I_t$,然后应用相同的游戏逻辑函数$f(I_t)$来更新状态[^2]。 - **优点**: - **高一致性**:由于逻辑在客户端本地执行,游戏状态在所有玩家设备上保持严格同步,适合对精度要求高的场景(如物理模拟)。 - **带宽效率**:只传输输入数据(如玩家操作),而不是整个状态,减少了网络带宽需求。例如,在低带宽环境中,每秒传输的输入数据量可能只有几KB。 - **缺点**: - **延迟敏感**:任何网络延迟都会导致帧卡顿或不同步,影响实时性。 - **实现复杂**:在UE中,帧同步通常需要自定义实现或使用特定插件(如Rollback Netcode),因为UE蓝图系统默认更偏向状态同步。 #### 2. **状态同步(State Synchronization)** - **核心机制**:状态同步由服务器(或权威主机)计算游戏状态,然后将状态变化直接发送给客户端。客户端不执行核心逻辑,而是接收更新后的状态(如玩家位置、生命值)并渲染显示。在UE中,这通过蓝图系统的“Replicated”变量实现,例如标记一个变量为`Replicated`,服务器会自动同步其值到所有客户端[^1][^3]。 - 示例代码(蓝图): ```cpp UPROPERTY(Replicated) float Health; // 健康值变量,标记为Replicated以实现同步 ``` - **优点**: - **灵活性高**:服务器可以处理复杂逻辑(如碰撞检测),客户端只负责渲染,减少客户端计算负担。 - **抗延迟性好**:客户端可以预测或插值状态变化,对网络抖动容忍度较高。 - **缺点**: - **带宽消耗大**:传输完整状态数据(如位置、旋转)可能占用较多带宽,尤其在高玩家数量的游戏中。 - **潜在不一致**:如果同步频率低,客户端可能出现短暂的状态不同步(如角色位置漂移)。 #### 3. **帧同步与状态同步的核心区别** 下表总结了两种技术的主要差异: | 特性 | 帧同步 | 状态同步 | |--------------------|-----------------------------------|-------------------------------------| | **同步对象** | 输入数据(如按键序列) | 游戏状态(如位置、生命值) | | **计算位置** | 客户端本地执行逻辑 | 服务器计算,客户端接收状态 | | **带宽需求** | 较低(只传输输入) | 较高(传输状态变化) | | **延迟影响** | 敏感(延迟导致帧不同步) | 较不敏感(客户端可预测状态) | | **实现复杂度** | 高(需自定义帧管理) | 低(UE蓝图内置支持) | | **一致性保证** | 高(所有客户端状态严格一致) | 中等(依赖同步频率) | 关键区别点: - **逻辑执行位置**:帧同步中,客户端是“主动计算者”,输入同步确保逻辑一致性;状态同步中,客户端是“被动接收者”,状态同步依赖服务器权威[^2][^5]。 - **网络架构适用性**:帧同步更适合P2P(点对点)或客户端-服务器架构中的轻量级同步;状态同步天然契合UE的客户端-服务器架构,服务器作为中央协调节点[^5]。 #### 4. **应用场景** 在Unreal Engine中,选择哪种同步技术取决于游戏类型和需求: - **帧同步适用场景**: - **高精度竞技游戏**:如实时战略(RTS)或格斗游戏,其中每一帧的计算必须完全一致(例如,《英雄联盟》使用帧同步变体)。输入同步确保所有玩家看到相同的单位移动和伤害计算。 - **低带宽环境**:移动端或网络条件差的场景,因为输入数据量小,减少卡顿风险。 - **示例UE实现**:UE本身不原生支持帧同步,但可通过插件(如Unreal Tournament的Rollback系统)或自定义C++代码实现。开发者需要手动管理帧时钟和输入队列。 - **状态同步适用场景**: - **大型多人游戏**:如第一人称射击(FPS)或MMORPG(如《Fortnite》),其中状态变化频繁(如玩家位置、道具拾取)。UE蓝图系统通过`Replicated`变量简化实现,例如同步玩家生命值或事件触发[^1][^3]。 - **复杂状态管理**:游戏有大量动态对象(如物理模拟的车辆),服务器可以高效处理状态更新。 - **混合精度优化**:在关键操作(如射击判定)使用高精度状态同步,其他场景用低精度以减少带宽,平衡性能与一致性[^2]。 混合方法:许多UE项目采用混合同步(如引用[2]提到的混合精度同步),结合两者优势。例如,在FPS游戏中,玩家移动使用状态同步,而技能释放采用帧同步输入,确保公平性。 #### 5. **在Unreal Engine中的实现建议** - **状态同步实现**:在蓝图中,直接使用`Replicated`属性- 变量:标记关键变量(如`Health`或`Position`),服务器自动同步- 函数:使用`RPC(Remote Procedure Call)`同步函数执行(如`Server_Attack`)[^1][^3]。 - **帧同步实现**:需要额外工作: - 使用UE的`NetDriver`和自定义时序逻辑。 - 推荐插件:如UE Marketplace的“Frame Synchronization Plugin”。 - **最佳实践**:测试网络条件(如高延迟模拟),使用UE的`Network Profiler`优化带宽。在客户端-服务器架构中,服务器应作为唯一权威源[^5]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值