Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved Destroy GameObject through ServerRpc

Discussion in 'Netcode for GameObjects' started by Pawli, Sep 12, 2023.

  1. Pawli


    Jun 25, 2020

    I am very new to Netcode and it's my first time using it, just a heads up.

    I want a client to press a button and upon that a tree (a GameObject) should be destroyed.
    The problem here is, that the tree is a NetworkObject and I want it to be destroyed on all clients.
    The call to destroy the tree should be made by a client though, but clients are not allowed to destory NetworkObjects. So I would send a ServerRpc and let the server destroy it.
    Now, how do I let the server know which GameObject it should destroy. Server RPCs only take non-nullable types as Parameters, so I cannot just pass the GameObject or the Transform of my tree as a Parameter for the RPC.
    I have multiple trees in the scene.

    Thanks for your help in advance.
  2. cerestorm


    Apr 16, 2020