'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);
}

EDIT: image of the components on the weapon

EDIT: This class extends a class that extends the networkbehaviour class. The objects are just sitting in the scene at start -- they are not spawned/instantiated (not sure if that matters or not).



Solution 1:[1]

The most plausible solution to this problem , either it is running into a error in some previous lines or as some other person pointed out , requireOwnership is not set to false . For in depth analysis of MLAPI , https://youtube.com/channel/UCBStHvqSDEF751f0CWd3-Pg I found the tutorial series on this channel best

Solution 2:[2]

I have the same issue. Been looking at it for 2 days but I am inclined to think it is a bug to be honest.

Solution 3:[3]

I needed to add the following attribute to my ServerRpc:

[ServerRpc(RequireOwnership = false)]

since the player was not the owner of the item.

Solution 4:[4]

I just spent 4+ hours banging my head against the wall because they didn't write this important info in the documentation. When calling ServerRpc from a client that doesn't own the Network Object, RPC attribute should be set to RequireOwnership = false.

Solution 5:[5]

For me the issue was that the GameObject(with NetwrokObject component) was sitting in the scene before starting the game, I couldn't use NetworkVariables nor ServerRpc. I think those are only usable on spawned object, but not sure. So I would say : either instantiate the object and add it to the NetworkManager or use normal variable on those objects.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sanchit Gupta
Solution 2 David
Solution 3 skon182
Solution 4 xyzferizman
Solution 5 edin