Search Unity

Dynamically spawned unknown Network Objects

Discussion in 'Netcode for GameObjects' started by addom34, Jun 10, 2023.

  1. addom34

    addom34

    Joined:
    May 24, 2015
    Posts:
    2
    Hey,
    I'm trying to set up a multiplayer app, where host spawns objects dynamically (when we start a host or client, we don't know what objects we will spawn - NetworkManager's prefab list is empty). When host creates a session and creates prefab which should be shared, adds handler to prefab override, prefab information (fbx model) is saved and send over network with Telepathy (TCP/IP client) to the joining client. It is possible that within one session there will be several different models shared over network, so we need to register new prefabs and remove old ones.
    Now my problem is that when I start client before I receive model information (fbx file), I get an error that there is no prefab register for given override, and object instantiated on client is not spawned (doesn't get transform updates). When I start client after receiving fbx file and setting prefab handler, it works fine for the first model. But when models changes and we receive a new model to be spawned, it's not spawned on client instance and transform changes are applied to the first model.

    My question is how to properly handle such scenario: we don't know what will be spawned over the network, so how to propagate model information and manage this model over network.
     
    Imm0rt4l_PL likes this.
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,005
    I would make sure that the game logic is separate from the visualization. You may not need and probably shouldn't have one prefab for each FBX. Instead, you'd have one or just a few prefabs (for a given type of model, like player character vs AI/CPU controlled or ragdoll vs non-ragdoll).

    That way, the prefabs can always safely spawn on clients, and transferring and loading the FBX file becomes an afterthought.

    What you do with that prefab instance between spawning it and until the FBX was received and applied to the MeshFilter / MeshRenderer is up to you. You may decide to display a loading animation, or just hide and pause that object, or use a dummy graphics in the meantime.
     
    Imm0rt4l_PL likes this.