Skip to content

Spawning prefab from in-scene NetworkObject results in "an object with that id is already in the spawned list" warning and "Size mismatch" warning #4087

Description

@zachstronaut

Description

I additively load a scene (and I am using Netcode's scene management). In that scene file there is a GameObject at the root with a NetworkObject and this script:

using UnityEngine;
using Unity.Netcode;
using UnityEngine.SceneManagement;

public class WarnTest : NetworkBehaviour
{
    public NetworkObject spawnPrefab;

    protected override void OnNetworkPostSpawn() {
        if (NetworkManager.IsServer)
        {
            NetworkObject childNetObj = GameObject.Instantiate(spawnPrefab, transform.position, transform.rotation);
            SceneManager.MoveGameObjectToScene(childNetObj.gameObject, gameObject.scene);
            childNetObj.Spawn(destroyWithScene: true);
            childNetObj.TrySetParent(transform);
        }
    }
}

The prefab I spawn is the simplest case... just a prefab with a NetworkObject. This prefab is in a manually created network prefab list that I have set in my NetworkManager.

This results in two warnings:

[Netcode] Trying to spawn a NetworkObject with a NetworkObjectId of 109 but an object with that id is already in the spawned list. This should not happen!

[Netcode] [null][Deserialize][NetworkBehaviourSynchronization][Size mismatch] Expected: 122 Currently At: 121!

(Please note that the second warning will cause a NullException without a patch fix applied for #4071)

Am I forgetting some rule about parenting or about spawning? What is the issue here? I'm not seeing my mistake in the docs.

Environment

  • OS: Windows
  • Unity Version: 6000.3.16f1
  • Netcode Version: 2.12.0 (although certainly not a new problem to this version)
  • Netcode Topology: Client-Server

Metadata

Metadata

Assignees

No one assigned

    Labels

    stat:awaiting-triageStatus - Awaiting triage from the Netcode team.stat:reply-neededAwaiting reply from Unity accounttype:bugBug Report

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions