Skip to content

SpawnManager.InstantiateAndSpawn doesn't Instantiate on Server #2911

@AsmPrgmC3

Description

@AsmPrgmC3

Description

SpawnManager.InstantiateAndSpawn doesn't instantiate the prefab when run on a server.

Reproduce Steps

  1. Add a cube to the scene with a Network Object component
  2. Create a prefab from that cube and add it to the Network Prefab list; remove the original from the scene
  3. Add an empty to the scene and add the following component:
using Unity.Netcode;
using UnityEngine;

[RequireComponent(typeof(NetworkObject))]
public class Spawner : NetworkBehaviour
{
    public NetworkObject prefab;

    public override void OnNetworkSpawn()
    {
        if (!IsServer)
        {
            return;
        }

        NetworkManager.SpawnManager.InstantiateAndSpawn(prefab);
        NetworkManager.SpawnManager.InstantiateAndSpawn(prefab);
    }
}
  1. Assign the cube prefab to the Spawner component
  2. Start the project as a server (not host)

Actual Outcome

The cube prefab never gets instantiated, causing:

  • No cubes get added to the scene/hierarchy
  • (Inside the Editor only) The first InstantiateAndSpawn causes the error Transform resides in a Prefab asset and cannot be set to prevent data corruption
  • The second InstatiateAndSpawn causes the error SpawnStateException: Object is already spawned

Expected Outcome

Two cubes spawn.

Environment

  • OS: Windows 10 (22H2)
  • Unity Version: 2022.3.7f1
  • Netcode Version: Release 1.8.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:highThis issue has high priority and we are focusing to resolve itstat:importedStatus - Issue is tracked internally at Unitytype:bugBug Report

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions