Search Unity

OnServerInitialized() not being called in C#

Discussion in 'Multiplayer' started by Lex, Sep 20, 2010.

  1. Lex

    Lex

    Joined:
    Dec 2, 2009
    Posts:
    43
    Any idea why the method OnServerInitialized() won't run in C# if it's in a script other than the one initializing the server?

    I mean, I have a ConnectionGUI script witch calls

    Code (csharp):
    1. Network.InitializeServer(32, connectPort);
    then later in this script I have:

    Code (csharp):
    1. void OnServerInitialized()
    2. {
    3.     Debug.Log("Server initialized and ready");
    4. }
    An in another script, the SpawnPlayer script I have the same function:

    Code (csharp):
    1. void OnServerInitialized()
    2. {
    3.     Debug.Log("Hi I'm OnServerInitialized too!");
    4. }
    The first one prints okay in the console but the second one is never called. Yes, scripts are attached to GameObjects and seem to run when in Javascript (at least worked when I was doing the tutorial I found).
     
  2. Lex

    Lex

    Joined:
    Dec 2, 2009
    Posts:
    43
    Nevermind, It I found out that the script wasn't working at all because I changed its name and forgot to rename the class... As it was already attached I didn't notice the mistake.. :roll:
     
  3. earthcrosser

    earthcrosser

    Joined:
    Oct 13, 2010
    Posts:
    122
    I'm having the same problem but I don't think I changed the name of anything, could you give a little more detail on what exactly happened?
     
  4. Dev_Max

    Dev_Max

    Joined:
    Aug 17, 2016
    Posts:
    1
    Look if you don't have a network identity that makes the gameobject disabled on play.