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

Trying to synchronize NetworkObjectId

Discussion in 'Netcode for GameObjects' started by reiconrooc, Jul 9, 2023.

  1. reiconrooc

    reiconrooc

    Joined:
    Aug 11, 2018
    Posts:
    16
    I am using netcode to spawn an object server side and synchronize that when a client next connect to server.
    I am getting this error: [Netcode] [Object Scene Migration] Trying to synchronize NetworkObjectId (2) but it was not spawned or no longer exists!!
    I have a single scene and I am not loading a second scene.
    What I am doing wrong? I use a my own method to instantiate and spawn the object:

    Code (CSharp):
    1. internal static T Instantiate<T>(string resourcePath, string name, bool active = true, bool spawn = true) where T : MonoBehaviour
    2.         {
    3.             T prefab = (T)Resources.Load(resourcePath, typeof(T));
    4.             prefab = Object.Instantiate(prefab);
    5.  
    6.             if (prefab != null)
    7.             {
    8.                 prefab.name = name;
    9.                 prefab.gameObject.SetActive(active);
    10.  
    11.                 NetworkObject netPrefab = prefab.GetComponent<NetworkObject>();
    12.                 if (netPrefab != null && spawn)
    13.                     netPrefab.Spawn();
    14.             }
    15.             return prefab;
    16.         }
     
  2. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    218
    You call this function only on the server and when a client tries to join you get the error?
    is this prefab registered in the netwrok manager prefab list?
     
  3. reiconrooc

    reiconrooc

    Joined:
    Aug 11, 2018
    Posts:
    16
    May be the problem is the netwrok manager prefab list: I thought the prefab were in the list, but not.
    I am dropping the prefab, but the inspector don't let me do it. There is an element called DefaultNetworkPrefabs.
    As I can remember, I have to put there. Is something changed?
     
  4. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    218
    In the new versions of netcode the network prefabs are in a sciptable object if I am not wrong. You need to put them in the object and then drag the object to the network manager. I am not sure how to do this.
     
  5. reiconrooc

    reiconrooc

    Joined:
    Aug 11, 2018
    Posts:
    16
    It seems you are right!! Thanks. Now the object is synchronized
     
    lavagoatGG likes this.