Search Unity

Interacting with child objects from spawned prefab

Discussion in 'Multiplayer' started by jendrikb, Jan 13, 2019.

  1. jendrikb

    jendrikb

    Joined:
    Sep 22, 2017
    Posts:
    12
    Hi,
    I´m really new to UNET and after hours of searching I´m not getting into solving my problem.
    I´m spawning a prefab with a lot of child objects. Parts of them are disabled, because I want to enable them while the game is running.
    I can enable (and see) them on client side, but it is not possible to make network calls on them, unless I click on "Spawn" in the NetworkIdentity component of this specific GameObject.
    So, they have to be "observed". But how the hell I force them to be observed? I don´t want to spawn every single child of my prefab throu the server. Or do I have to?

    After activating there is no NetworkID for this GameObject:
    upload_2019-1-13_22-55-34.png

    Here is the Spawn Button I´m talking about:
    upload_2019-1-13_22-55-50.png

    After I clicking it...
    upload_2019-1-13_22-57-10.png

    ...my code for this Object is working:

    Code (CSharp):
    1. [SyncVar(hook = "OnTap")]
    2.     bool isactive;
    3.  
    4.     void Start()
    5.     {
    6.         isactive = true;
    7.     }
    8.  
    9.     [Command]
    10.     public void CmdPickUp()
    11.     {
    12.         isactive = false;
    13.         print("pickupServer");
    14.     }
    15.  
    16.     void OnTap(bool enable)
    17.     {
    18.         gameObject.SetActive(enable);
    19.     }
     
  2. jendrikb

    jendrikb

    Joined:
    Sep 22, 2017
    Posts:
    12
    Additionally info: It is a non-player object.