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. Dismiss Notice

Having issues with my first Connected Game.

Discussion in 'Multiplayer' started by ecfelts, Nov 14, 2020.

  1. ecfelts

    ecfelts

    Joined:
    Aug 7, 2017
    Posts:
    11
    Hello,

    I have been teaching myself programming by putting together a Turn-Based Multiplayer board game and I have seen a few issues that seem to be interrelated. I am new to all of this, so if there is a better place to be posting a question like this, point me in the direction and I will take it there.


    The first issue is that the game often skips turns or gives players a half of a turn… Depending on what mood the network is in.


    The second issue is that the problem gets noticeably worse when I am running it from nodes separate from my own machine.


    To be more specific, when I run several instances of the game from my machine, everything seems to run ok until I get four or five players. But when I run the game from multiple machines, the game skips turns much more frequently.

    All I have to go on is an error “Refused to get unsafe ETag.” in the browser consoles. When doing a Google search for that error, I get a lot of word salad of very specific but unhelpful technical jargon.

    I feel like somewhere along the line packets of information are getting dropped and different player’s boards stop agreeing with each other with regard to what it is that they are supposed to be doing or where they are at in the turn order…

    Is this anything that sounds familiar to anyone?

    I am using PhotonEngine (Photon.Pun and Photon.Realtime) for all of the networking. Is there any other information I could provide to make my question more helpful..?

    Is this something that there is a best practices doc for..? Or a lesson already written for that I should be looking at..?

    Thanks in advance for any insight or direction that anyone might be able to provide...
     
  2. ecfelts

    ecfelts

    Joined:
    Aug 7, 2017
    Posts:
    11
    Is there any way that I could have formed this question that would have improved my chances of getting any sort of response...?

    Or am I just being impatient and not waiting long enough...?
     
  3. Cranom

    Cranom

    Joined:
    Jan 31, 2018
    Posts:
    26
    Hi, so you start learning programming by making a multiplayer game ? I'm familiar with the expression "going from zero to pro!" but that's taking it to the next level right there "cutting the bullshit and starting from pro!".
    Well, you could start by debugging from there. If you already encounter a problem in local no need to add even more difficulty, find out why four or more players is problematic, is it your code or room size limitation from Photon or just a bad network setup ? Also describe how turns are handled and how server/client is done.

    So yeah, your problem is quite open ended, you need to isolate each part and add on as you go. Test with no netcode, then with netcode executed localy and finally over a true network.
     
    ecfelts likes this.
  4. ecfelts

    ecfelts

    Joined:
    Aug 7, 2017
    Posts:
    11
    A voice in the darkness..!!!!

    Thank you..!!!

    I am not sure what you are referring to by "netcode". When you say "A bad network set up" are you referring to bad hardware...? Like the physical network itself is limiting in some way...?

    My question may seem open-ended because I have a concern that when I am too specific in describing my issue people just don't want to read all of that stuff and just blow past my question. I have never had a lot of luck coming to forums, so they really are the venue of last resort for me.
    ----
    break here while I go and test stuff...
    ----
    I was a bit vexed by your comment initially, because that is human nature, but I went back and re-examined my code and *did* find an issue.

    To open, the process you describe is pretty much what I did... No net code, netcode local, then netcode with friends and family.

    I may have implemented netcode too soon though because I was not sure how much of a pain it would be to retrofit everything to make use of netcode once I was done with the game itself. Maybe a rookie mistake, but as I said, I am self-taught so I am sure that everything under the hood is a rat's nest.

    The specific error I found had to do with counting the number of players in the room. I know that I should be able to get the number of players in the room from the server, but I never had very much luck making that happen so I came up with a workaround.

    I set up a coroutine to count the players once everyone got into the room. (don't laugh. I am new at this...) It turns out that the coroutine was not giving everyone enough time to load into the game before counting the players and that was making everything else fall apart. That is also why the issue was only happening with more players.

    I am still having an issue where the game loses connectivity after a while *BUT* it is losing connectivity in a fairly predictable manner, whereas before all sorts of inconsistent craziness was going on.

    Thank you again for the nudge. It really helped a lot..!!!
     
  5. Cranom

    Cranom

    Joined:
    Jan 31, 2018
    Posts:
    26
    I'm no pro either, glad you didn't get offended, it wasn't the intent.

    When i say netcode i mean code you wrote whith multiplayer intent by using a network stack such as Photon in your case.
    When i say bad setup i refer to your network stack manager wich contain generic info to work properly: https://doc.photonengine.com/en-us/pun/current/getting-started/initial-setup

    As for making a game multiplayer from the get go, yes it it better to do so on a project that envision multiplayer as a goal but only if you already know the how-to. Teaching yourself in so many aspects has a tendency to lenghten the trip and discourage people. Regardless of whether it's good or not, you're free to make this choice!

    There is nothing to laugh at your problem and it's pretty much the main source of error you're gonna get with multiplayer: timing.

    I don't know how much you did, but maybe try making it as barebone as possible, players connecting are added at the end of turn order, and only when pressing a touch is their turn ended, then add a timer for timeouts to auto-end turns.
    Since you're starting your journey in multiplayer it could be a simple mistake in your Client/Server communications. I would recommend you to go on the Photon website for documentation, demos and tutorials, and precise help since i'm not familiar with Photon.
     
    tobiass likes this.