Search Unity

Sigleton pattern bad idea for multiplayer?

Discussion in 'Scripting' started by ViCoX, Sep 19, 2014.

  1. ViCoX

    ViCoX

    Joined:
    Nov 22, 2013
    Posts:
    37
    Hi Unitynauts,

    I`m thinking about implementing state machine for my game that handles states trough singleton. Will this cause me problems when converting my game to multiplayer? (as you can only one in each scene)

    Or should I go with some other messaging system or pattern? I would appreciate if you could point me to right direction. What are your multiplayer experiences with singletons?

    Thanks a lot,
    - J
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,692
    It depends on your multiplayer design. If it's a traditional client/server design, it should be fine to use a singleton in a client, since it will only apply to the local player. For the server side, and in general (in my opinion), it's better to avoid singletons when possible. You never know when you'll end up needing more than one instance of something.

    Since multiplayer has such a big impact on your game's architecture, it's a good idea to get it working (or at least prototyped) from the start. It's much harder to force it into a single-player architecture after the fact.
     
    ViCoX likes this.
  3. ViCoX

    ViCoX

    Joined:
    Nov 22, 2013
    Posts:
    37
    Thanks TonyLi for a simple good answer! : )

    I am already planning it in some level, but I want to approach this by first making something playable and reliable.
    (Basic movement, cameras and such) I`m not so keen on using the assets from the store as I`m new to unity and they tend to confuse me more that writing my own.

    I`m planning on using uLink so I think it will handle most of the server side quite well out of the box?

    Thanks
    - J
     
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,692
    I've never used uLink. All I can recommend is to make a series of prototypes -- one for multiplayer networking, one for movement and camera, one for AI, etc. They just need to be proofs of concept, not final products. This will give you an idea of how everything will eventually work together, without having to invest a lot of time going down a bad route. Then you can pull in the code -- or more likely just the design lessons -- into your main project. Good luck!
     
    ViCoX likes this.
  5. ViCoX

    ViCoX

    Joined:
    Nov 22, 2013
    Posts:
    37
    Good advice!

    I did that with my verlet simulator for the game and definetly should do the same with networking, gameplay and AI.
    Ohhhh the challenges are soo vast in the world of games!
    I have background in VFX and its all about one shot and angle haha : )

    Thanks,
    - J