Search Unity

How to iterate through spawned objects? ( #MLAPI - 0.1.0 or 0.2.0 )

Discussion in 'Netcode for GameObjects' started by bindon, Aug 1, 2021.

  1. bindon

    bindon

    Joined:
    May 25, 2017
    Posts:
    20
    I have been trying to use NetworkList to create a, well, network list of all my spawned game objects that have been spawned from a prefab of a particular kind (ie. all the game objects that I have spawned on the clients from a given prefab), and then referring to that list on a client.

    upload_2021-8-1_9-12-50.png

    I find NetworkVariable works no trouble.
    And NetworkList works ok with a list of integers.

    But when I add a spawned NetworkObject to a NetworkList on the server,
    on the client the, although the list item exists, it's contents is null.

    Please could you say if
    (1) this is a bug, or
    (2) I am doing something wrong, or
    (3) I have fundamentally misunderstood how I'm supposed to be using MLAPI

    upload_2021-8-1_9-23-40.png

    Also it would be really helpful to me if anyone can point me towards an implementation of an INetworkVariable for a simple class { } eg. a class containing a string and an int ... I think I can extrapolate from there. (Very grateful !)
     
    Last edited: Aug 1, 2021
  2. firaui

    firaui

    Joined:
    Nov 14, 2018
    Posts:
    12
    You can use NetworkSpawnManager class to iterate object that already spawned. It works both in server and client.

    Code (CSharp):
    1. NetworkManager.SpawnManager.SpawnedObjects
    2.  
    3. // or
    4.  
    5. NetworkManager.SpawnManager.SpawnedObjectsList