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.

Question Add Network Object to a scene dynamically

Discussion in 'Multiplayer' started by HankMerr, Sep 29, 2022.

  1. HankMerr

    HankMerr

    Joined:
    Sep 20, 2022
    Posts:
    5
    Hey,

    i have a scene where i am importing models on runtime (OBJ / FBX).

    When importing a model on the host i would need to give the information what model it is to the client, so the client could import the same model.

    Now I want to use those on runtime imported models as Network Objects to do some collaborative work with the models on Host or Client (transformation).

    But they are not registered prefabs. Is there a way to register those new objects on runtime? Can i set the GlobalObjectIDHash myself on those imported objects so they would match?

    Any help would be great,

    Thanks,

    Hank
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    1,866
    You can just make a stand-in prefab for your models with a NetworkBehaviour and a NetworkVariable that contains the path to the model, and of course a MeshFilter and MeshRenderer but it suffices to assign it a cube.

    You can then spawn as many of these stand-ins as you like, assign the path to the NetworkVariable which causes clients to receive the OnValueChanged event upon which they load the appropriate model.

    However, you will have to transfer the model to the clients in some way. I'm working on a FileTransfer for Netcode asset that'll allow you to do that at runtime.
     
    HankMerr likes this.
  3. HankMerr

    HankMerr

    Joined:
    Sep 20, 2022
    Posts:
    5
    Wow yes thanks thats a good idea, your FileTransfer for Netcode Tools sounds very cool - Thanks !