vault backup: 2024-10-12 17:19:45

This commit is contained in:
2024-10-12 17:19:46 +08:00
parent ff94ddca61
commit 244c0c52f6
960 changed files with 31348 additions and 10 deletions

View File

@@ -0,0 +1,48 @@
# Client
- **功能描述:** 在Client-owned的Actor上PlayerController或Pawn执行一个RPC函数只运行在客户端上。对应的实现函数会添加_Implementation后缀。
- **元数据类型:** bool
- **引擎模块:** Network
- **作用机制:** 在FunctionFlags加入[FUNC_Net](../../../../Flags/EFunctionFlags/FUNC_Net.md)、[FUNC_NetClient](../../../../Flags/EFunctionFlags/FUNC_NetClient.md)
- **常用程度:★★★★★**
在Client-owned的Actor上PlayerController或Pawn执行一个RPC函数只运行在客户端上。对应的实现函数会添加_Implementation后缀。
一般用于从Server发送一个RPC到Client。和蓝图里RunOnClient的效果一样。
所谓Client-owned参考文档[https://docs.unrealengine.com/4.27/zh-CN/InteractiveExperiences/Networking/Actors/RPCs/](https://docs.unrealengine.com/4.27/zh-CN/InteractiveExperiences/Networking/Actors/RPCs/)
![Untitled](Untitled.png)
## 测试代码:
```cpp
UCLASS(Blueprintable, BlueprintType)
class INSIDER_API AMyFunction_PlayerController :public APlayerController
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Client, Reliable)
void MyFunc_RunOnClient();
};
void AMyFunction_PlayerController::MyFunc_RunOnClient_Implementation()
{
UInsiderLibrary::PrintFuncStatus(this, TEXT("MyFunc_RunOnClient_Implementation"));
}
```
测试蓝图PIE模式一个ListenServer+2Client
![Untitled](Untitled%201.png)
## 测试输出结果:
```cpp
MyFunc_Client_Implementation BP_NetworkPC_C_0 NM_Client Local:ROLE_AutonomousProxy Remote:ROLE_Authority
OtherClientFunc BP_NetworkPC_C_0 NM_Client Local:ROLE_AutonomousProxy Remote:ROLE_Authority
```
可见测试代码中取第2个PC发出一个Run on Client的RPC调用最终在Client上成功触发。C++定义的函数和蓝图中添加的自定义RunOnClient事件效果是等价的。
而如果这个函数在Server owned Actor上执行则只会在运行在服务器上不会传递到客户端。

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB