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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

User interfaces in multiplayer game

Discussion in 'General Discussion' started by Merchant1307, Jan 12, 2018.

  1. Merchant1307

    Merchant1307

    Joined:
    Jan 29, 2016
    Posts:
    33
    Should I be having the canvas inside of the player gameobject so it is his hpbar etc or does each user get the same scene replicated for themselves?
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Unless you're talking about multiplayer on 1 screen, then technically everyone has a copy of everything (that's shared).
    What values you show/update, etc are user depedent.

    Imagine I was playing a game and you were another player. We'd both have a canvas with our health bar, but mine would be showing me my health and you yours.
     
  3. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,314
    i guess your players prefab for local and remotes are identical?

    so i would do something like this:

    Code (CSharp):
    1. void OnLoadPlayer(bool local)
    2. {
    3. if(local == false) return;
    4.  
    5. var uiHealthBar = Instantiate(Resources.load("UI/HealthBar")).getcomponent<UiHealthBar>();
    6. uihealthbar.AttachPlayer(this);
    7. }
    so you have one canvas in Resource/UI/HealthBar.prefab this way your scene stay clean.
     
  4. Merchant1307

    Merchant1307

    Joined:
    Jan 29, 2016
    Posts:
    33

    I'm talking about mmo type of multiplayer and ui.

    So say I do in code :
    castBar = GameObject.Find("CastingBar").GetComponent<CastingBar>();

    there would be no errors of everyone using the same canvas in the scene because its a duplicate for themselves and it finds the casting bar on their duplicate?

    Also is it better to serialized field it instead of find it this way?
     
  5. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Yes, that's how it'd be, if there was just 1 casting bar per scene. It would be for the player. :)

    Yes, to your second question, too. Always avoid GameObject find if you can.
     
  6. Merchant1307

    Merchant1307

    Joined:
    Jan 29, 2016
    Posts:
    33
    It was a way to hard code instead of using the inspector and there would only be one gameobject named CastingBar.

    I've been trying to find information on serialized fields when I would want to avoid using them and why I would want to use them over hardcoding the find which would seem more reliable than something set in the inspector or atleast everything seems more setup in the code.
     
  7. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Well, a couple of issues with find are speed and potential errors. Since you pass a string, you might mistype it or rename the object. The speed issue is that it searches everything in the scene until it finds a match.
    variables you assign in the inspector are a lot more reliable and a lot faster.
     
  8. Merchant1307

    Merchant1307

    Joined:
    Jan 29, 2016
    Posts:
    33
    So the outside put into the inspector will always override default as well as start initializations?
     
  9. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    inspector values will replace a class declaration line, but not something done in Start().
     
  10. Merchant1307

    Merchant1307

    Joined:
    Jan 29, 2016
    Posts:
    33
    back to the ui, lets say I had a singleton class spellbook attached to the spellbook ui, this singleton has its own copy per person as well right, its no different?
     
  11. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Ya, it should be that way (as in you should make sure it's so).
    Like, on the client's copy of the running game, only that local / client player should try to access "their own" stuff. Nothing is literally shared in a multiplayer game. Stuff appears to be shared, by passing data around..Right? :)

    In other words, so long as you don't let some other player (other than the client) access the client's singleton or anything else exclusively theirs, everything should be okay :)

    Hope that makes some sense.
     
  12. Merchant1307

    Merchant1307

    Joined:
    Jan 29, 2016
    Posts:
    33
    Well I want to be able to access the singleton for spell/attack effects from other players however I want it to be only effecting that players spellbook they are attacking with the skill disable or similar.
     
  13. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Not sure I totally understand what you're saying, sorry.
    Are you currently working on the game? Is it working okay? :)
     
  14. Merchant1307

    Merchant1307

    Joined:
    Jan 29, 2016
    Posts:
    33
    would each person get their own static singleton or would they all pull from the same static singleton.
     
  15. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    If each client gets the singleton, everything should be okay so long as you aren't trying to sync anything from it to everyone.
     
  16. elmar1028

    elmar1028

    Joined:
    Nov 21, 2013
    Posts:
    2,353
    Clients can't pull from the same static singleton. Which machine would host that singleton?

    A better solution would have server react to changes in the world (e.g. player dies, respawns etc.) and transmit data to connected clients. Those connected clients would then update their singletons.

    This way, you only transmit values only when they're changed. And bandwidth is kept minimal.
     
  17. Merchant1307

    Merchant1307

    Joined:
    Jan 29, 2016
    Posts:
    33
    I'm still at low level csharp learning quickly and networking has always been intimidating to me and I want to learn more about it.

    I'm not sure what you mean by which machine hosting the singleton. The singleton would be attached to that player by being a part of his ui aka on his spellbook panel and I want each player to have his own instance of that spellbook for his own recharges/cast times to be altered during gameplay.

    Is networking going to be hard to learn for an mmo?

    A better question, Once I have the game in a single player state playable and setup to attack players or enemies will multiplayer implementation be complicated to learn?
     
    Last edited: Jan 26, 2018
  18. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Well, I will offer a general answer to that.

    Before you learn networking for programming (and/or game making), you should learn programming. Do not try to program network stuff first.. unless you're just having a bit of fun. :) That's up to you.

    If you feel comfortable at making a game, and then want to make a network multiplayer game, then you should begin the game with networking in mind from the very beginning.

    If you want to learn more about networking, and you are already somewhat decent at programming, I would suggest that you try some general networking (ie: not really try to make the game work).
    If you only want to know a simple game for Unity, you can try their HLAPI and or LLAPI and see how that works.

    This answer is pretty general, because I wasn't sure about your experience, necessarily. And it's all just my opinion, but hopefully it makes some sense. :)
     
  19. Merchant1307

    Merchant1307

    Joined:
    Jan 29, 2016
    Posts:
    33
    I'm reaeding on unitys hlapi right now, would you recommend learning php and some mysql for saving stuff?
     
  20. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Well, like I said, my suggestion would be to make sure you're okay with programming to begin with.
    Then, if you're trying the HLAPI just try some simple things like sending data back n forth that you can read (or execute methods or sync variables, in the case of the HLAPI).

    As for php and mysql, I've never used either, but if they are something you need/want later, then I guess learning them would be important :)
     
  21. Merchant1307

    Merchant1307

    Joined:
    Jan 29, 2016
    Posts:
    33
    Is csharp adequate enough to communicate with databases to not need php in gaming(aside from displaying the same information on a website)? Is there any upsides php has on csharp?
     
    Last edited: Jan 29, 2018
  22. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,092
    Yes. Though depending on the database you may need a library (usually supplied by the company that makes it).

    MySQL, for example, would use the following library: https://dev.mysql.com/downloads/connector/net/