Hi there. So i have a prefab that gets instantiated in the network and if it collides with an object with the tag “PizzaLay”, will parent with that object and also make the object itself kinematic.
Everything works fine except the parenting, the host can do it perfectly, but the client can’t since it drops this error: NotServerException: Only the server can reparent NetworkObjects
I need both Client and Host be able to do that, i know that only the “server” can do it and for that reason i used ServerRpc and even ClientRpc to execute the parenting code, none of them work though.
Any wonder of what’s going on? Here’s the code:
public void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "PizzaLay")
{
PizzaPub = col;
countinglife = false;
lifetime = 0f;
PlayerMovementSOLO.inst.IngCount++;
AssignParentServerRpc();
AssingParentClientRpc();
}
}
[ServerRpc(RequireOwnership = false)]
public void AssignParentServerRpc()
{
rb.isKinematic = true;
rb.detectCollisions = false;
gameObject.transform.SetParent(PizzaPub.gameObject.transform);
}
[ClientRpc]
public void AssingParentClientRpc()
{
rb.isKinematic = true;
rb.detectCollisions = false;
gameObject.transform.SetParent(PizzaPub.gameObject.transform);
}
Any suggestion is hapily recieved. Sorry for my bad spelling, idk a lot about english