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,52 @@
# Server
- **功能描述:** 在Client-owned的Actor上PlayerController或Pawn执行一个RPC函数只运行在服务器上。对应的实现函数会添加_Implementation后缀
- **元数据类型:** bool
- **引擎模块:** Network
- **作用机制:** 在FunctionFlags中加入[FUNC_Net](../../../../Flags/EFunctionFlags/FUNC_Net.md)、[FUNC_NetServer](../../../../Flags/EFunctionFlags/FUNC_NetServer.md)
- **常用程度:★★★★★**
在Client-owned的Actor上PlayerController或Pawn执行一个RPC函数只运行在服务器上。对应的实现函数会添加_Implementation后缀。
和RunOnServer的效果一样。
所谓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, Server, Reliable)
void MyFunc_RunOnServer();
};
void AMyFunction_PlayerController::MyFunc_RunOnServer_Implementation()
{
UInsiderLibrary::PrintFuncStatus(this, TEXT("MyFunc_RunOnServer_Implementation"));
}
```
测试蓝图PIE模式一个ListenServer+2Client
![Untitled](Untitled.png)
## 测试输出结果:
```cpp
LogInsider: Display: 5118b400 MyFunc_RunOnServer_Implementation BP_NetworkPC_C_1 NM_ListenServer Local:ROLE_Authority Remote:ROLE_AutonomousProxy
LogInsider: Display: 44ec3c00 MyFunc_RunOnServer_Implementation BP_NetworkPC_C_2 NM_ListenServer Local:ROLE_Authority Remote:ROLE_AutonomousProxy
LogInsider: Display: 49999000 OtherServerFunc BP_NetworkPC_C_1 NM_ListenServer Local:ROLE_Authority Remote:ROLE_AutonomousProxy
LogInsider: Display: 4bcbd800 OtherServerFunc BP_NetworkPC_C_2 NM_ListenServer Local:ROLE_Authority Remote:ROLE_AutonomousProxy
```
可见测试代码中取第2个PC发出一个Run on Server的RPC调用最终在Server上成功触发。C++定义的函数和蓝图中添加的自定义RunOnServer事件效果是等价的。
而如果这个函数在Server owned Actor上执行则只会在运行在服务器上不会传递到客户端。

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 KiB