简体   繁体   English

客户端由于某种原因未调用服务器RPC

[英]Server RPC is not called by client for some reason

So I have just started working on a new project in Unreal which is intended to be a simple networked multiplayer game. 因此,我刚刚开始在Unreal中进行一个新项目,该项目旨在成为一个简单的网络多人游戏。 What I have done so far is make a Weapon class that handles the spawning of projectiles, and give the player character an instance of a weapon on BeginPlay. 到目前为止,我所做的是制作一个Weapon类,用于处理弹丸的生成,并为玩家角色提供BeginPlay上的武器实例。

The weapon class is simple, but the problem that I am having is that the Server RPC I have for spawning projectiles is not being called from clients, only servers. 武器类很简单,但是我遇到的问题是,我没有从客户端调用服务器生成RPC的服务器RPC,而仅从服务器调用了RPC。

Here is how I am calling this RPC: 这就是我称之为RPC的方式:

The Player Character has an OnFire method, that is bound to an input action. 玩家角色具有一个OnFire方法,该方法绑定到输入操作。 This then calls the Fire method on the current weapon that the player has. 然后,这将对玩家拥有的当前武器调用Fire方法。

// Bind fire event
PlayerInputComponent->BindAction("Fire", IE_Pressed, this, &AMultiplayerFPSCharacter::OnFire);

 ...

 void AMultiplayerFPSCharacter::OnFire()
 {
      // Call our weapon's fire method
      if (CurrentWeapon)
      {
          CurrentWeapon->Fire(GetControlRotation());
      }
 }

Now, the weapon's Fire method simply calls the Server RPC to actually handle spawning the projectiles. 现在,武器的Fire方法只需调用Server RPC即可实际处理生成的弹丸。

 void AWeapon::Fire(const FRotator SpawnRotation)
 {
      UE_LOG(LogTemp, Warning, TEXT("LOCAL Fire"));


      Server_Fire(SpawnRotation);
 }

 void AWeapon::Server_Fire_Implementation(const FRotator SpawnRotation)
 {
    UE_LOG(LogTemp, Warning, TEXT("SERVER RPC: Called RPC"));


    // try and fire a projectile
    if (ProjectileClass != NULL)
    {
        // Spawn Projectile
        ....
    }
 }

I also have the validation method for the Server RPC, which simply returns true for this so I can make sure it actually works. 我还有Server RPC的验证方法,为此它只返回true,因此我可以确保它确实有效。

This implementation is all fine and good on the server or Listen-Server, but when I call it from the client I only get the local Fire method on the Weapon. 这种实现在服务器或Listen-Server上都很好,但是当我从客户端调用它时,只能在Weapon上获得本地Fire方法。 The client never even calls the server RPC. 客户端甚至从不调用服务器RPC。

One work around that I think I have found is to make the Player Character's OnFire method a Server RPC as well, but this feels like it is not the best way to go about doing this. 我想我发现的一种OnFire方法是也将Player Character的OnFire方法也设置为Server RPC,但这似乎并不是实现此目的的最佳方法。

Could anyone explain why this is happening? 谁能解释为什么会这样?

A client can only call a server RPC on a net-owned actor. 客户端只能在网络参与者上调用服务器RPC。 For example, a client net-owns his PlayerController, so you can add a RPC to that, and call it. 例如,客户端拥有自己的PlayerController,因此您可以在其中添加一个RPC并调用它。 If you call it on a server-owned object, like I'm assuming your AWeapon actor is, the log will show something like "can't call RPC on non-owned object". 如果您在服务器拥有的对象上调用它,例如我假设您的AWeapon actor是,则日志将显示类似“无法在非拥有对象上调用RPC”的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java XML RPC客户端和服务器 - Java XML RPC Client and server RPC C ++服务器和Python客户端 - RPC C++ server and Python client 确定与 COM RPC 服务器通信的客户端进程的进程 ID - Determine the Process ID of the Client Process communicating with a COM RPC Server rpc和普通tcp / udp服务器客户端程序之间的区别? - difference between rpc and normal tcp/udp server client program? 如何从客户端关闭gRPC服务器(使用RPC功能) - How to shutdown gRPC server from Client (using RPC function) 异步服务器停止从客户端获取数据,没有明显的原因 - Asynchronous server stopping getting data from client with no visible reason 如何使用Win RPC发送终止的char数组(用于将映像从客户端上传到服务器) - how to use win RPC to send terminated char array(use to upload image from client to server) 如何将可变长度字符串从RPC服务器传递到客户端? - How can I pass a variable-length string from an RPC server to the client? 为对等系统编写C ++客户端/服务器的最佳RPC软件包是什么? - What's the best RPC package to write a C++ client/server for a peer-to-peer system? 有没有我可以用来在C ++中实现RPC(客户端-服务器)的设计模式? - Is there design patterns I can use to implement an RPC (client-server) in C++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM