Need some help deciding whether to modify Unet source code.

  • Hi, I’m new to C# world, and
    currently trying to make a simple RPG

(I first appologize for not
being able to speak English

  • What I’m trying to accomplish is the
    following: In my game, once a client
    has all the players spawned in
    his/her local scene, I would like to
    execute a function on each of
    instances running the same game. The
    function simply initializes several
    variables for the player and store
    them locally. I will call this
    function SetupControllers(), and it
    contains an operation which counts
    player objects that have currently
    been spawned. I will write cnt to
    indicate the counted number.

  • The problem is: I can’t find an
    approperiate function to override
    from NetworkLobbyManager.cs which
    will excute SetupControllers().

  • I jumped into networking library
    source code on this repository :

  • Here are what I found out so far :

  1. I tried to overload some functions that was marked as “virtual”: OnClientConnect(), OnClientSceneChanged(), OnStartClient(). But CNT from SetupControllers() returns 0 on client side.

  2. I continued to dig the source code of networking library, and I’ve found a function which I hoped it to be marked as “virtual”, but unfortunately was not. It was OnOwnerMessage() in ClientScene.cs under UnityEngine.Networking. It is a delegate which is invoked once a client receives message of which msgType is MsgType.Owner.

  • So, I would like to ask:
  1. Would it be a good idea to customize the networking library,
    and add a public delegate which in
    turn would be invoked inside

  2. If not, am I missing any callback functions that was already mentioned
    on this page?

  • I tried my best to make this question
    clear as possible.
    I’m willing to
    provide further information to
    solve this problem. Thanks in advance :slight_smile:

EDIT: I finally managed to solve it by using the method @Honorsoft suggested. Many Thanks!

I experimented with networking in Unity using Photon and another method other than Unet (I forget the name, but uses public servers). I have switched back to Unet because although those networking solutions have a lot of stuff built-in, I don’t like how that stuff is made. I think it would be better to build upon the standard Unet source code.
Also, there might be a simpler way (and possibly better too) to achieve the results you are looking for, other than having to overload functions. For example, you could just have the variables initialized as the player objects are created in the game. I’m not sure why you would need to overload functions to do what you describe, but I’ve done more complicated setups than that just using scripts attached to objects or prefabs. If you don’t want the player objects initialized right away, you can just have a script that sets a timer.