Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Destroy GameObject through ServerRpc

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

  1. Pawli

    Pawli

    Joined:
    Jun 25, 2020
    Posts:
    1
    Hi,

    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

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    603