I am working on a VR game and trying to handle ball grabbing for balls which originally belong to the server, the ServerRpcs do not run on clients, only on the Host if they grab a ball. I tried removing (RequireOwnership = false) and even got an error complaining that I should be using it when trying out grabbing a ball as a client, but when I do use it there is no error and no Debug.Logs from inside the ServerRpc calls. The script is as follows (IMPORTANT: this is a copy of the script with a lot of my notes and unused methods removed, for simpler navigation, the script being used by the objects is named NetworkThrowable.cs):
using UnityEngine;
using MLAPI;
using MLAPI.Messaging;
using Valve.VR.InteractionSystem;
public class TestNetworkThrowable : NetworkBehaviour
{
private Interactable thisInteractable;
public void OnGrabbed()
{
ServerMethodGrabServerRpc();
}
[ServerRpc(RequireOwnership = false)]
private void ServerMethodGrabServerRpc()
{
Debug.Log("Before changeownership owner id: " + GetComponent<NetworkObject>().OwnerClientId);
GetComponent<NetworkObject>().ChangeOwnership(NetworkManager.Singleton.LocalClientId);
Debug.Log("After changeownership owner id: " + GetComponent<NetworkObject>().OwnerClientId);
}
[ServerRpc(RequireOwnership = false)]
private void ServerMethodLetGoServerRpc()
{
Debug.Log("Before removeownership: " + GetComponent<NetworkObject>().OwnerClientId);
GetComponent<NetworkObject>().RemoveOwnership();
Debug.Log("After removeownership: " + GetComponent<NetworkObject>().OwnerClientId);
}
public void OnLetGo()
{
ServerMethodLetGoServerRpc();
}
protected Hand.AttachmentFlags attachmentFlags = Hand.AttachmentFlags.DetachFromOtherHand;
private GrabTypes grabbedWithType;
private Vector3 lastHandProjected;
private Hand _hand;
private void HandHoverUpdate(Hand hand)
{
_hand = hand;
GrabTypes startingGrabType = hand.GetGrabStarting();
bool isGrabEnding = hand.IsGrabbingWithType(grabbedWithType) == false;
if (grabbedWithType == GrabTypes.None && startingGrabType != GrabTypes.None)
{
grabbedWithType = startingGrabType;
// Trigger was just pressed
hand.AttachObject(gameObject, startingGrabType, attachmentFlags);
hand.HoverLock(thisInteractable);
hand.HideGrabHint();
Debug.Log("Test grabbed!");
OnGrabbed();
}
else if (grabbedWithType != GrabTypes.None && isGrabEnding)
{
grabbedWithType = GrabTypes.None;
Debug.Log("Test let go!");
OnLetGo();
}
}
}
The inspector for the throwables looks like:
