Reputation: 1
I am making a game where the player is a spaceship that flies between planets. When the ship lands on a planet, it should parent to that planet to keep it from falling off. This works fine for the host player, however client players will not reparent to the planet objects, and no errors are given. Through experimentation, it seems the RPCs aren't even being called.
Please advise on any methods I can use to set and clear the parent of the player ship.
Parent to Nearest Body is a script called in the Update of the Ship script, which is the player controller script.
public class Ship : NetworkBehaviour
{
void ParentToNearestBody()
{
if (Vector3.Distance(transform.position, nearestBody.transform.position) < (snapHeight + nearestBody.radius))
{
//The ship is close enough to land, parent to the planet
ParentToObjectServerRpc();
}
else
{
//Clear parent
ClearParentServerRpc();
}
}
[ServerRpc]
public void ParentToObjectServerRpc()
{
NetworkObject.TrySetParent(nearestBody.gameObject, true);
}
[ServerRpc]
public void ClearParentServerRpc()
{
NetworkObject.TryRemoveParent(true);
}
}
I have tried transform.parent = nearestBody (the error suggested to use NetworkObject.TrySetParent()) I have tried NetworkObject.TrySetParent without the RPC function. I have tried replacing the contents of the rpc with a debug log or a command to quit the application, neither executed on the client.
Upvotes: 0
Views: 189