Reparent player to networkObject

I am trying to reparent the player into a networkObject’s child (a car seat for instance).

I am doing this by raytracing from the player to the vehicle, and activate a “take control” script on the vehicle, which turns on and off stuff.

Now in order to actually do the reparenting I need to do this on the server, so in the vehicle’s “take control” script I activate a ServerRpc to handle the reparenting with the client’s local networkId.

I get an Error saying only the owner can send an ServerRpc with reparenting. What is happening here? I tried to move the reparenting ServerRpc and call to the method into the player’s “interact” script, but the same issue comes up.

I don’t have any of the code on this machine, but hopefully this is enough to get a general guide and workflow on how to approach this. If not I’ll update this with the relevant code.

Some notes:
At this moment, the networkObject I’m trying to reparent TO is already in the scene from start, and not spawned in after server start. I don’t know if this can cause an issue regarding networkObjectId or spawnedObjectsList?

Might need to see the code and the full error, but it could just be a case of needing to use

[ServerRpc(RequireOwnership = false)]

if you don’t have ownership on the object you’re calling from.

1 Like

Thank you for the quick response.

I’ll post the error and relevant code when I get home from work.

I contemplated doing that, but avoided it due to believing it’s bad practice. I may try this when I get home.

Bonus question: I see that someone reparents by calling ServerRpc, which gets the networkObject’s networkId, then trigger the reparenting on ClientRpc. I haven’t tried this, but wouldn’t that also throw the error for only server being able to reparent?

I would have thought so but I’ve not tried it, I’ve only ever handled parenting on the server on object spawn.

1 Like

Perhaps they were reparenting to the root (i.e. to null)? That is as far as I know the only reparenting that a client can do itself.

1 Like

After trying around more, I decided to go with the tip of just disabeling ownership requirement for the ServerRpc

Hey, I had that problem too. I didn’t disable ownership but instead of reparent a NetworkObject, I am doing this:
Scene

  • I have a NetworkObject with a list of custom Prefabs that need to be instantiated (not the NetworkManager list)
  • I have a NetworkTransform LootBubble (Registered in the NW Manager)
  • The player is a NetworkObject and registered in the NW Manager (the player has bone object where I need to place the weapon)
  • The weapon registered has a number of the position in the custom PrefabList
    Runtime:
  • At collision with the Lootbubble i take read the position in the PrefabList from the weapon
  • On The server I instantiate the weapon and add it to the place in the PlayerPrefab as a child (ServerRPC)
  • Then i do the same on all Clients (Client RPC)

Maybe that helps you too