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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unet, Spawning the player prefab manually

Discussion in 'Scripting' started by panicq, Jun 29, 2015.

  1. panicq

    panicq

    Joined:
    Sep 29, 2012
    Posts:
    37
    Hi,

    I'm trying to do a team based prototype with unet. I'm trying to spawn the player prefab after the client has connected to the server and has chose his/her team. The first thing I did is to uncheck the Auto Create Player in my NetworkManager. Then I've found the NetworkServer.AddPlayerForConnection(conn, player, playerControllerId) method, but it needs a connection and a playerControllerId parameter that are passed when the OnServerAddPlayer method is called. But it's not called because of the Auto Create Player set to false.

    Do you have an idea of how I can achieve this ?

    Thx in advance :)
     
    stawrocek likes this.
  2. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    I'm also looking into this. Try running the code from OnServerAddPlayer or cache the connection from that function somewhere and run it where you're trying to. That's what I'm going to try momentarily.

    And of course I mean to run the code in the appropriate event. I'll probably get this wrong a few times as it's all new to me :D

    --edit

    It would appear I can't figure it out. My answer until further notice is screw it & make your default player an empty object that can run the functions you want to run before spawning its body.
     
    Last edited: Jul 10, 2015
    stawrocek likes this.
  3. panicq

    panicq

    Joined:
    Sep 29, 2012
    Posts:
    37
    :/ In my case I have let the default player spawn and disabled all the renderers and the input scripts. I then added a "PlayerStatus" scripts that re-activates the renderers and the input scripts as soon as the player select his/her team. It works but it's not really nice :D
     
    Tomnnn likes this.
  4. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    We're making the best of what's built in and easy to use haha