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

Resolved Spawning Host as different Prefab

Discussion in 'Netcode for GameObjects' started by erik969, Aug 12, 2023.

  1. erik969

    erik969

    Joined:
    May 10, 2020
    Posts:
    7
    I'm making a game where the host spawns in as a totally different prefab than the rest of the players and I can't for the life of me figure out how I can spawn in a player that doesn't share the same prefabs as the rest.
     
  2. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    598
    If you leave the Player Prefab field of the network manager blank you can spawn your own player network objects with NetworkObject.SpawnAsPlayerObject.

    Another option is to set the player prefab hash in Connection Approval.
     
    erik969 likes this.
  3. erik969

    erik969

    Joined:
    May 10, 2020
    Posts:
    7
    Ok, so I went with the second option you gave me and I'm having some issues.

    I copied the ConnectionApproval and ClientConnectionHandler script that's in the page that you linked but now I'm confused as to where to place them or how to use them.

    I think I'm supposed to put the ClientConnectionHandler in the player prefab that is instantiated by default and run the SetClientPlayerPrefab function on Awake but it doesn't seem to do anything.

    Edit: Solved! I just had to copy/paste the ConnectionApproval script, modify the PlayerPrefabHash and run the Setup function with a button
     
    Last edited: Aug 12, 2023
    cerestorm likes this.