- Home /
Unity MLAPI ServerRPC not getting called
I'm implementing a system in which a player can pickup an item from the game world. After picking the item up, I want to destroy the game object. To do this, I figured I'd make a ServerRPC that deletes the object, but the ServerRPC is not getting called. I tried making a ClientRPC as well, but that one isn't being called either. I noticed that it only gets called when the host of the game tries to pick up the item -- any ideas on how to fix this? The documentation is pretty bare but please let me know if I missed anything. Here is my code:
 public override void Interact(GameObject player)
 {
     player.GetComponent<PlayerInventory>().AddItem(this.item);
     Debug.Log("before");
     TestClientRpc();
     TestServerRpc();
 }
  
  
 [ServerRpc]
 public void TestServerRpc()
 {
     Debug.Log("server");
     // Destroy(gameObject);
 }
  
 [ClientRpc]
 public void TestClientRpc()
 {
     Debug.Log("client");
     // Destroy(gameObject);
 }
Answer by salem_tanios · Apr 16, 2021 at 07:04 PM
i think you have to put [ServerRpc(RequireOwnership = false)] if you're not the owner
Your answer
 
 
             Follow this Question
Related Questions
Animation Update for the TPS controller 1 Answer
RPC Calls in 5.1 0 Answers
Interchange player names in Multiplayer game 1 Answer
How Client send info to Host in Unity Multiplayer 0 Answers
hi i need help with code 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                