Search Unity

Tanks Multiplayer - complete networking project (Netcode, Photon)

Discussion in 'Assets and Asset Store' started by Baroni, Jun 11, 2016.

?

Which networking solution would you like to use with this asset?

  1. Unity Networking

    136 vote(s)
    51.5%
  2. Photon Networking

    98 vote(s)
    37.1%
  3. Other

    30 vote(s)
    11.4%
  1. pandey611

    pandey611

    Joined:
    Sep 26, 2013
    Posts:
    14
  2. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    @pandey611 That forum was shut down 2 years ago. This is the thread for support, you can ask here.
     
  3. ZevsMMA

    ZevsMMA

    Joined:
    Mar 30, 2022
    Posts:
    3
    We have such a problem, a room is created from the android, and the second player enters through the PC, but when the phone is blocked in android, or when you go to the phone menu, the server stops
     
  4. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    @ZevsMMA mobile phones do not execute networking requests in the background. Otherwise this would mean massive data consumption, e.g. if the user just forgot to shut down the app. This is a general disadvantage of client hosted games, not the asset specifically.

    You did not write which networking provider you are using, but using Photon incorporates host migration so the master client is transferred to another player instead of stopping completely. Alternatively you may want to look into dedicated server hosting, if that is your requirement.
     
  5. ZevsMMA

    ZevsMMA

    Joined:
    Mar 30, 2022
    Posts:
    3
    I set it up via photon, but there is no installation for the mirror on the documentation, how can I put it on a dedicated server? to fix the problem
     
  6. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Mirror networking support will be removed soon, I do not recommend going that way. Photon has a standalone build too, if host migration is not enough. The official Photon documentation has several guides for their server build and outlines some requirements.

    Please note that dedicated server support is not something that can just be turned on or off as you like - the code needs to be designed to work with it. Currently there have been a few developers who were able to deploy the game on a server with modifications, but support for dedicated servers is not built in (and as such not advertised).

    Another note: PC builds do not stop client hosted games in the background as they continue to run. This makes desktop builds more suited for hosting, instead of mobile. Unfortunately for mobile phones, it's just how they work - the main processes are halted when the app is set to the background.
     
  7. ZevsMMA

    ZevsMMA

    Joined:
    Mar 30, 2022
    Posts:
    3
    I sometimes have such a problem, the second player enters the room, but gets into another, like a new room is created, that is, he gets into another room
     
  8. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    "Sometimes" is a difficult term in regards to reproduction. This is likely caused by your network because as you wrote, you are mixing mobile and desktop? Here are some key points why that would happen:

    - in online mode, the cloud server decides which players are matched together depending on their geographical location, ping and discovery timeout
    - in LAN mode, there is a discovery timeout of 8 seconds. With a temporary bad connection, this could get reached
    - in all modes, only users who selected the same game mode (team deathmatch or capture the flag) are matched together

    If one of these values are deemed to not match, the timeout is reached and the user creates his own room.
     
  9. jjdomain

    jjdomain

    Joined:
    Sep 11, 2015
    Posts:
    93
    Thanks for the advice!
     
    Baroni likes this.
  10. stanleykwan

    stanleykwan

    Joined:
    Nov 18, 2021
    Posts:
    6
    Hello, I am new to Photon, for the game using PUN2, if update database is required, should it be the task of the "MasterClient" do? Or it could be do it in the Photon side?
     
  11. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Hi there, I am not sure what you mean by "update database". Do you mean a database query that should be executed or requested in the game? If that's the case, the asset does not implement any database, so it seems more like a general question you could also ask on the Photon forums. Personally, I would recommend having each client request database changes on its own, but have that checked and executed on the backend servers only.

    The MasterClient would not be the correct way to implement this since if the host is hacked/cheating, it could issue faulty requests for everyone in the room. Again, you would want to verify using official Photon documentation and forums.
     
  12. stanleykwan

    stanleykwan

    Joined:
    Nov 18, 2021
    Posts:
    6
    Thanks a lot for the quick and detailed reply. Because I would like to save the player profile like accumulated score and some other data to the database. If using Photon PUN2, so the best way should be done in the client side. Is it the same way to do if using Mirror?

    Thanks a lot.
     
    Last edited: Aug 25, 2022
  13. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Makes sense! The networking provider (Photon/Mirror/etc) is actually unrelated to this. It would work the same for all networking solutions, unless you have a dedicated server running, which could execute the query directly (after some sanity checks).
     
  14. stanleykwan

    stanleykwan

    Joined:
    Nov 18, 2021
    Posts:
    6
    Thanks a lot for your help :D
     
  15. Hedeag

    Hedeag

    Joined:
    Feb 10, 2015
    Posts:
    29
    Hello, where is the name of the scene, if I want to specify another scene, instead of TDM_Game, where can I specify it
     
  16. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Hi @Hedeag, the matchmaking filter is applied on the scene file name. If you would like to add another TDM map, just name the scene file TDM_<mapname>. More details are found in the documentation pdf included, chapter 5.4 "Game Modes".
     
  17. DejaVuQuest

    DejaVuQuest

    Joined:
    Dec 22, 2021
    Posts:
    1
    Why this error comes when in fresh install the Asset. TY
    upload_2022-10-3_10-23-19.png
     
  18. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    It seems like you imported a Tanks Multiplayer network package, but did not import the network asset. You have to import the Unity Netcode or Photon sources separately, please see documentation PDF.
     
  19. toni8989

    toni8989

    Joined:
    Jun 24, 2013
    Posts:
    2
    Hello

    When I select a different tank from default always default one is spawned. Don't know why. I checked that all the tanks are in network. I'm using Photon
     
  20. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Hi @toni8989, thank you for the report. I discovered a similar bug few weeks ago that could be related to this. On the Products game object in the Intro scene and its "Toggle Group" component, could you try to enable "Allow Switch Off" and see if this solves it?

    upload_2022-10-29_10-42-7.png

    Otherwise, you would look at the NetworkManagerCustom script, line 319 and put a Debug.Log below to find out what the player's tank value is and whether it changes on a different selection.
     
  21. toni8989

    toni8989

    Joined:
    Jun 24, 2013
    Posts:
    2

    Still not working, going to set the debug. Thanks for the fast response.
     
  22. navagames

    navagames

    Joined:
    Jun 5, 2015
    Posts:
    3
    I am using netcode, i've been debugging NetworkManagerCustom and can not for the life of me figure out how playerPrefabs is getting populated with the 3 tanks. Its not in the editor anywhere i can find for NetorkManagerCustom. Can you tell me how public GameObject[] playerPrefabs; is already populated with the 3 tanks
    ? Thank you.
     
  23. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Hi @navagames, good catch - it was definitely there in the inspector before, it must have been changed with a Netcode update since the NetworkManager script does not show any custom variables at all.

    You can still make it visible on the NetworkManager prefab and here's how: when selected, click the top right dots in the inspector and select Debug state. The script will then show custom variables like the playerPrefabs array, but no built-in ones.

    upload_2022-11-27_0-17-1.png

    Thanks again for posting here, I have to investigate where and why this was changed.
     
  24. navagames

    navagames

    Joined:
    Jun 5, 2015
    Posts:
    3
    Thanks! I didn't even know this feature existed in unity. I was completely out of ideas. I will need to read up on editor debug, and curious on what you discover since there are a lot of differences in variable access between normal/debug. I think I'm most curious on how you intend it to be working.
     
  25. gamer2300

    gamer2300

    Joined:
    Jan 16, 2013
    Posts:
    31
    Hello i buy tanks multiplayer to use with netcode. After read and execute instructions in first chapter of manual i note that in netcode 1.0.2 there is not not an example about ClientNetworkTransform to download like Bootstrap. So i continue install and make network setup until it says Ok you can run intro scene. So when run scene object are not sinced at all. how must solve this? Seems that in LAN mode two instance can connect because the player have cprrect name but the rest like since movements of tanks (proiectiles are spawned by invisible tanks..and mesh of tanks is at the begin position) not work. how solve this?
    I find an issue..on tankfree prefab is missing a script and i have not errors
    another issue when i run an instance on mobile device other instance say..IndexOutOfRangeException: Index 0 is out of range in container of '0' Length.
     
    Last edited: Dec 4, 2022
  26. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Hello @gamer2300, thank you for the report. I looked into the issues and saw that Unity basically broke all existing netcode synchronization by doing this change, where network variables cannot be changed anymore before the object is spawned. This affects powerups and projectiles in the game. Additionally, they removed the ClientNetworkTransform component.

    I am currently working on refactoring the code and make it work again as before, with the goal of having an update ready tomorrow (Monday). Thank you for your patience!
     
  27. gamer2300

    gamer2300

    Joined:
    Jan 16, 2013
    Posts:
    31
    Look what happen when compile in my pc..compiler say..
    Script attached to 'TankSilv' in scene '' is missing or no valid script is attached.
    UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
    the same for other tanks..
    i wait a valid package soon from asset store
     

    Attached Files:

  28. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Yes that will be fixed tomorrow as well.
     
  29. gamer2300

    gamer2300

    Joined:
    Jan 16, 2013
    Posts:
    31
    Hello, i try 1.6.3 now all seems ok. I have some questions, with 2 players for example is normal that game quit when one of two player dead? there is a mode to not quit and dont repeat the lauch of the player inside game? if i want different group of players in the same (i mean real room) room how i can differ servers? can you create a different panel where user use the concept of login with classic NetworkUImanager? i think is better if user can choose how connect with others. For example if i create a game with only two player how can make other two player with different game (i mean another instance like server/client of the same game) in the same network Wifi?

    Excuse me i want put another note about quit game when one player dead..or pheraps the correct term is when only one player is live in scene. at this moment game quit but if one player only is in the scene can be the case for example that player win so how i can differ from quit for some problem and quit because only one player is in game because wins?

    another problem when i try to reconnect with a live instance ( i use a pc and an android at this time, but project must go only on mobile) i see this error...
    Invalid allocation label passed to UnsafeUtility::Free
    UnityEngine.StackTraceUtility:ExtractStackTrace ()
    Unity.Netcode.FastBufferWriter:Dispose () (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.2/Runtime/Serialization/FastBufferWriter.cs:125)
    TanksMP.NetworkDiscovery/<ReceiveBroadcastAsync>d__29:MoveNext () (at Assets/TanksMultiplayer/Scripts/NetworkDiscovery.cs:287)
    UnityEngine.UnitySynchronizationContext:ExecuteTasks ()

    instead when i try to make first player on android and second on pc Unity3d hangs! Or give an error
     

    Attached Files:

    Last edited: Dec 4, 2022
  30. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Version 1.6.3
    The following bug fixes are all related to the Unity Netcode 1.1.0 update
    - Netcode: fixed NetworkManager inspector not showing own+inherited variables @navagames
    - Netcode: fixed synchronization of players due to missing ClientNetworkTransform @gamer2300
    - Netcode: fixed NullReferenceException when collecting powerups on clients @gamer2300
    - Netcode: fixed wrong turret rotation due to ClientNetworkTransform interpolation @gamer2300

    @gamer2300 the update was released at midnight, you were quicker than me :)

    Not sure what you mean by "quit". Players are respawned when they die, until the score in the GameManager is reached. If the host disconnects, all clients disconnect too - that is normal, since host migration is only supported with Photon. The host stopping when a client quits on the same machine is a bug in Unity Netcode.

    Each client determines if it needs to create a room. If all existing rooms are full, the client creates a new room. I think what you are asking is a lobby with display of rooms, but that feature would need to use a separate server or the Unity Lobby service, which also has additional costs. The goal for this asset was to serve as a template mostly for mobile use, where quick-join (1 button) is the most common way.

    I am sorry, I still do not understand. Your sentences regarding this seem to be missing some important words to make sense.

    This is a Unity Netcode bug. I could not see any gameplay problems caused by that error, but Unity needs to fix it.

    Most, and even modern Android devices are not able to host a game with a desktop PC joining it, because of firewall and port forwarding issues. I noticed this myself in the tests yesterday. Since the existing code works for desktop-desktop (host-client) games, this seems to be again a Unity Netcode issue. I do not think they have fully tested Wi-Fi connections in their current release yet. You might want to create a thread in the Unity Netcode section of this forum to clear things up!
     
  31. ahmetteksas

    ahmetteksas

    Joined:
    Aug 19, 2021
    Posts:
    7
    Hello @Baroni , I am wondering that if I can enable bots in online game? If yes, then how can I do that? For instance, if room has 2 players and 6 bots then someone entered to the room and then one of the bots must be disabled. Thanks
     
  32. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Hi @ahmetteksas, unfortunately this is currently not supported. I have answered that question a while ago, please see this post. Basically the PlayerBot script needs to be fully rewritten to be network compatible. Neither the movement using NavMesh is synchronized, nor the player detection and shooting.

    If you would like to give it a go, you would take a look at the PlayerBot script and start with these methods. There are some decisions you have to make during the process, e.g. how you want to synchronize the movement: let the master client generate a waypoint and send that position to all other players doing their own (local) calculation, or just attach a NetworkTransform component on the bots and taking the overhead.

    Making bots online compatible is actually the bullet point for the next update.
     
  33. M4vm

    M4vm

    Joined:
    Aug 21, 2022
    Posts:
    1
    The joysticks disappear after i build the project , how do i fix this ?
     
  34. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    The (left/right) joystick is a mobile control. When building for platforms other than mobile, they are disabled using platform conditional defines. You can see this in the GameManager script.

    What platform are you building on or would like to use them?
     
  35. NewbNinja

    NewbNinja

    Joined:
    Jan 6, 2023
    Posts:
    1
    Is there any further simple demos to help get started modifying this code?

    Perhaps tasks like:

    In-App Purchases / Store Related:

    - Add a new tank
    - How to change price
    - Making a list and displaying items in a grid

    Game Related:

    - Adding a new game mode
    - How to send and retrieve server held variables

    Just to name a few? It's a great codebase but would be super helpful to have simple Get Started functions like this.
     
  36. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Please see this guide.

    That's not really related to the asset though, more general questions. You should change IAP prices in the App Store dashboard (Apple App Store / Google Play, ...) not in the game. And regarding list+grid, that would be a common UI topic covered by the Vertical / Horizontal Layout component or in any YouTube video for UI in Unity.

    This one is not that simple, as it not only requires major code changes, introduces new maps and splits your playerbase (each game mode has a separate matchmaking queue). It really depends on what your game mode should do. But, if you would like to just add a new mode without any code changes yet (which is basically up to you), please see chapter 5.4 of the documentation PDF, where the required changes are explained.

    I would assume that the documentation PDF covers this in great detail already, if you follow along from the start, since each game feature makes use of a different networking feature for demonstration purposes. There are two options for this: RPCs and NetworkVariables. Chapter 3.2 (Shooting) first introduces RPCs, then chapter 3.3 (Properties) follows with NetworkVariables. Both use cases are implemented in the Player script.
     
  37. yardom78

    yardom78

    Joined:
    Apr 30, 2021
    Posts:
    6
    Hi, I have few questions, understand I have no idea how multiplayer games are working so it could look bit stupid.

    1. I have a mobile game similar to a classic chess game. Can I use Tanks multiplayer as a template? I mean I just need that player clicks button "player vs player" and player will be automatically connected to another player.
    2. Does my game need to be somewhere on server or this template allows me to create p2p where 1 is host and 2 is client?
    3. Can I use this template to make my game a server application and put it on dedicated server and then make my game a client version?
     
  38. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Hi @yardom78! No worries, it's better asking now than later :)

    1. You could, however a chess game is really far away from a realtime multiplayer fighting game. Besides the basics and learning how the different network approaches work in Tanks Multiplayer, you will probably use nothing else of it. I would recommend going straight for Photon PUN, which has a lot of free, very basic samples. They will get you started more quickly than a complete network game.
    2. A host can also be a client. So, one player can host a game and the other player joins it.
    3. In relation to the previous question, dedicated server builds are not supported by this asset. Server builds require other coding than master-client builds, that has not been the focus when designing it.
     
  39. Brandgage-1

    Brandgage-1

    Joined:
    Nov 15, 2017
    Posts:
    32
    Is LAN Network Discovery supported for both NGO and PUN2 modes? If so, are there pros cons to one framework implementation over the other for Network Discovery specifically?
     
  40. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    LAN Discovery is not really a thing with Photon PUN2 since you need to host your own server in the LAN (a standalone application you have to install and run), see this documentation page. As such, LAN Discovery is not supported with PUN.
     
  41. Brandgage-1

    Brandgage-1

    Joined:
    Nov 15, 2017
    Posts:
    32
    Thanks for the resposne. ND It is implemented for NGO however?
     
  42. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Yes, Network Discovery fully works with NGO, however that is part of version 1.6.4 which is scheduled for release in 1-2 weeks. A major rewrite of the old implementation was necessary to work with newer versions of NGO.
     
  43. skhan2523

    skhan2523

    Joined:
    May 26, 2016
    Posts:
    16
    Sorry if it a little unrelated to your asset, But I am also using NetworkDiscovery. I am able to see available servers in LAN but when client attempts to connect to it after almost a minute it timesout. My firewalls on both server and client side were off.
     
  44. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    @skhan2523 The NetworkDiscovery component in this asset has been completely rewritten. It does not use the same techniques as in the original Netcode package anymore, since that stopped working completely at some point. If you do not own this asset, we are basically using two different components.
     
    skhan2523 likes this.
  45. skhan2523

    skhan2523

    Joined:
    May 26, 2016
    Posts:
    16
    So in your asset the network discovery can find all the servers in lan and client can connect to any of it? and it can be used as standalone in any other project? please confirm this
     
    Last edited: May 19, 2023
  46. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    The NetworkDiscovery component used was written for this asset and therefore fits into its overall design. It detects open servers on LAN and joins the first one with the selected game mode (being deathmatch or capture the flag) automatically.

    It cannot just copy pasted into another project because of this. If you want to display a list of open games and not do the auto-join, it would need to be modified.
     
  47. skhan2523

    skhan2523

    Joined:
    May 26, 2016
    Posts:
    16
    ok thank you.
     
  48. sofabivaadin

    sofabivaadin

    Joined:
    Apr 7, 2022
    Posts:
    6
    Hi,

    i'm dealing with a strange issue the remote player get jittering when i move my local player.

    i'm using mirror for networking and unity 2020.3.48.
    im using the 1.6.1 of your multiplayer tank

    I touch nothing i just import the project can you help me ?

     
    Last edited: Jun 9, 2023
  49. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Hello @sofabivaadin, support for Mirror networking has ended early 2022 as mentioned here. Where did you get a version that old?

    The jitter seen when moving upwards result from a network update rate that is too low or when not using movement interpolation, but instead fixed update positions (so technically the player jumps from point to point).
     
  50. sofabivaadin

    sofabivaadin

    Joined:
    Apr 7, 2022
    Posts:
    6
    When i don't move the local player and just move the remote player i don't see the jitter appears ?

    how the network update rate can be too low i test on local and how the network cannot use interpolation ? i don't touch network transform.

    I really don't understand