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. marvoules

    marvoules

    Joined:
    Sep 12, 2020
    Posts:
    1
    hi I have a question how can I add bots so when people enter my photon online if there are no more actual players in the room they can still play against mobile bot player
     
    ay0w likes this.
  2. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Hi @marvoules, there was a similar discussion on the last page of this thread, please start reading from here:
    https://forum.unity.com/threads/tan...lapi-photon-mirror.410465/page-7#post-7880281

    Currently bots cannot be mixed with the online mode as they are not fully "networkable". I am looking into this for one of the next updates, so bots could be added and then removed when another player joins. Feel free to go ahead and try it out yourself! The BotSpawner component in the game scene would be your first entry point for this.
     
    ay0w likes this.
  3. Kbosei6

    Kbosei6

    Joined:
    Oct 27, 2021
    Posts:
    2
    Please i cant find the scenes folder in the asset after downloading...But the tutorial video shows there should be a scenes folder when importing...PLease help me fix it.
     

    Attached Files:

  4. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    @Kbosei6 The YouTube video is years old, it was just reuploaded last year for the older versions. There are no scenes if you do not read the first chapter of the included documentation PDF. You have to decide for a network provider and run the "Window > Tanks Multiplayer > Network Setup" as written there. The game scenes come with the network package.
     
  5. ryan007007

    ryan007007

    Joined:
    Aug 8, 2014
    Posts:
    3
    Tanks Multiplayer - During my iOS Apple review, I got the following comment:

    When validating receipts on your server, your server needs to be able to handle a production-signed app getting its receipts from Apple’s test environment. The recommended approach is for your production server to always validate receipts against the production App Store first. If validation fails with the error code "Sandbox receipt used in production," you should validate against the test environment instead.

    Do I need to implement the additional "Simple in app purchases" asset and rebuild in order to get an acceptable storefront?
     
  6. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    No, the Simple IAP System asset is completely optional. The rejection you got may also be with general issues they are having when trying out your in-app purchases. Please see this thread for more information, which also states:
    The asset does not do any server validation so the rejection reason is misleading. In fact, it does not do any validation at all. You could try adding Unity IAP's local receipt validation, but that could or could not solve it. If you have tested in-app purchases on your local device and Testflight, and they work fine on your end, I would just try submitting the build again with a message telling them.
     
  7. lukezinsan

    lukezinsan

    Joined:
    Jan 16, 2014
    Posts:
    19
    hi.. i bought your asset. and i want to ask about how to know your team win or lost, I want to replace the game over display with the caption, "you win" or "you lose"
     
  8. ryan007007

    ryan007007

    Joined:
    Aug 8, 2014
    Posts:
    3
    You were right. I just resubmitted the app and it went through just fine. Thanks!! https://apps.apple.com/us/app/dimpty/id1602850668
     
    Baroni likes this.
  9. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Hi there, thanks for your purchase!

    In the UIGame script, SetGameOverText method, the winning team is passed in as an argument. In case you haven't noticed, the game displays a "team name WINS" message right before the game over screen. If you would like to change that to "YOU" win/lose, you could compare the team with the local player:
    Code (CSharp):
    1. bool didWin = GameManager.GetInstance().teams[GameManager.GetInstance().localPlayer.GetView().GetTeam()].name == team.name;
    2. gameOverText.text = didWin == true ? "YOU WIN!" : "YOU LOSE!";
    You did not tell which networking provider you are using, so I just assumed you are using Photon.
     
  10. lukezinsan

    lukezinsan

    Joined:
    Jan 16, 2014
    Posts:
    19
    hi.. thanks for fast answer, i will try it
     
  11. lukezinsan

    lukezinsan

    Joined:
    Jan 16, 2014
    Posts:
    19
    its work.. thanks..
    more question is, how we know if one or other team disconect from game, and its show "YOU LOSE" and the other team in game show YOU WIN, iam using photon

    thanks :)
     
  12. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    @lukezinsan I'm not really getting your question. Could you explain, what is the relation between disconnecting from the game and your end screen?
     
  13. lukezinsan

    lukezinsan

    Joined:
    Jan 16, 2014
    Posts:
    19
    can i contact your email? i will explain it
     
  14. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    @lukezinsan I do not provide private one-on-one asset support via email, sorry. This is the place to ask support questions, as the answers could be useful for other users as well.
     
  15. lukezinsan

    lukezinsan

    Joined:
    Jan 16, 2014
    Posts:
    19
    ok, my game only uses 2 teams, each team is 1 player (1v1). if one player exits the game (disconnect) then the player will display "You Lose" and the player who is still in the game room will display "You Win", is that possible?

    thanks..
     
  16. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Ah, only two players, I understand. You can make use of Photon callbacks for that:

    - OnLeftRoom (local user left the room)
    - OnPlayerLeftRoom (remote user left the room)

    The UIGame script already has an implementation for OnLeftRoom at the very bottom. You could check if the game is still in progress (!GameManager.GetInstance().IsGameOver()) and then display the "You Lose" UI, instead of loading the intro scene directly.
    Similar to this, implement the OnPlayerLeftRoom method, check if the game is still in progress and then display the "You Win" UI.

    There are, of course, also other possible approaches to this, but using Photon's callback system is usually a good idea.
     
  17. lukezinsan

    lukezinsan

    Joined:
    Jan 16, 2014
    Posts:
    19
    great..
    thanks for fast answer..
    i will try it
     
  18. lukezinsan

    lukezinsan

    Joined:
    Jan 16, 2014
    Posts:
    19
    hi.. i try your script.. and i got error
    this is my script

    public override void OnPlayerLeftRoom(Photon.Realtime.Player other)
    {
    if (!GameManager.GetInstance().IsGameOver())
    {
    Debug.Log("YOU WIN : PLAYER " + other.NickName + " is OUT");
    statusWinDisconnect.text = "You Win";
    }
    }

    its show error

    InvalidOperationException: Collection was modified; enumeration operation may not execute.
    System.ThrowHelper.ThrowInvalidOperationException (System.ExceptionResource resource) (at <9577ac7a62ef43179789031239ba8798>:0)
    System.Collections.Generic.List`1+Enumerator[T].MoveNextRare () (at <9577ac7a62ef43179789031239ba8798>:0)
    System.Collections.Generic.List`1+Enumerator[T].MoveNext () (at <9577ac7a62ef43179789031239ba8798>:0)


    any idea how to solve this?
    thanks
     
    Last edited: Mar 9, 2022
  19. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Is the exception coming from the IsGameOver() call? I'm not sure, since you did not post the root error, or a line mentioning the originating script. It could be that the callback is executed too early, when the GameManager has not fully initialized yet. But difficult to tell without knowing the root cause.
     
  20. lukezinsan

    lukezinsan

    Joined:
    Jan 16, 2014
    Posts:
    19
    hi.. i got error


    NullReferenceException: Object reference not set to an instance of an object
    TanksMP.PlayerBot+<DetectPlayers>d__13.MoveNext () (at Assets/TanksMultiplayer/Scripts/PlayerBot.cs:98)
    UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <17ad9609ae064f2c9315931ff97adcf1>:0)
     
  21. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Well there are multiple checks in that code line, you may want to verify whether GetView() and GetTeam() returns the expected result. Unfortunately it is impossible to know what you did or modified with just the error.
     
  22. lukezinsan

    lukezinsan

    Joined:
    Jan 16, 2014
    Posts:
    19
    oh.. oke.. but in other scene its run normaly.. :)
     
  23. lukezinsan

    lukezinsan

    Joined:
    Jan 16, 2014
    Posts:
    19
    its solve..
    error occurs because there is another object with layer player

    thanks for great support.. great asset.. i like it
     
    Baroni likes this.
  24. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    For future reference, this type of response is useless for troubleshooting...
     
  25. Zumy16

    Zumy16

    Joined:
    Apr 30, 2022
    Posts:
    1
    Hi, I have downloaded this file but every time I try to open it. It does not open and crashes and leads me to the hub. Can you pls help me? To elaborate further, I have to be able to open in unity to do the networking right? But I can't open it in unity at all.
     

    Attached Files:

    Last edited: Apr 30, 2022
  26. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Hi @Zumy16, sorry to hear the trouble on import. It sounds like your Unity project got in a corrupt state. Could you try to delete the TanksMultiplayer folder locally, then open the project via Unity Hub again? And yes, the network setup needs to be done in Unity after import.

    Unfortunately there is not much I could do to assist, since project issues are out of my reach. If you are unable to import in any project, you would also try deleting the asset unitypackage from the Asset Store folder locally and try downloading it again, as that could be corrupt too. As a last resort, open a ticket with Unity support directly.
     
  27. Geoffc

    Geoffc

    Joined:
    Feb 4, 2013
    Posts:
    39
    Hello. Does this asset have a way to allow users to register and save their username and keep their match details and scores in a database?
     
  28. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Hello @Geoffc, the username and score values are available. Submitting them to a database is not in scope of this asset, since there are hundreds of different database providers, so this would be something you would do on your own.
     
  29. Geoffc

    Geoffc

    Joined:
    Feb 4, 2013
    Posts:
    39
    Can I use a photon server with this by using an IP address of the server running photon SDK and not a PUN cloud game ID? or would mirror be a better choice for self-hosted?
     
  30. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    @Geoffc You can use either one. What networking provider best to use is up to your preference, but generally, personally I would avoid Mirror and the implementation is also being removed soon.
     
  31. Geoffc

    Geoffc

    Joined:
    Feb 4, 2013
    Posts:
    39
    ok, I have it working with the photon server :) would be good to have a waiting room example so players get taken to a game waiting room before the game begins instead of being dropped right into the game. So the game begins in xx seconds but only if there are a set number of players (like 2 or more). or dropped into the game like they are now but with a count down to when the game will start so players get taken to a game that has not started already.
     
  32. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Thanks for the feedback! The main idea of this asset was the "immediate action" approach, with only one button to jump straight into a game. More commonly used on mobile platforms. There might be a waiting room of some sort for an upcoming battle royale update. However a dedicated lobby is out of scope and part of another multiplayer asset I'm currently working on.
     
  33. giftgamebr

    giftgamebr

    Joined:
    Dec 8, 2021
    Posts:
    11
    Hello friend, I really liked your assets, I'm using the simple IAP and multiplayer tank system. would like some paid help, to integrate everything with playfab and photon SDK tournament. you can help me ? please get in touch with the email giftgamebr@gmail.com
     
  34. Agi356

    Agi356

    Joined:
    Nov 26, 2021
    Posts:
    1
    Hey there and thanks for the support you provide here! The documentation and especially the video on getting started with the project were very helpful.

    We implemented some changes using a script that affects certain attributes of the player (like move speed, mesh size or activation of powerups) after specific conditions are met.
    When playing against bots, all of that works fine, but in a multiplayer match (LAN) only the hosting player has access to these changes.

    Do you have any suggestions on how we could activate networking for such a script? The goal would be for it to affect each player individually with visual changes of a tank being visible to others in the same match. (For example, one player does something to make his tank grow smaller/larger and the other player can see that mesh also change on their end)

    Also, on a more general note, do you have any recommendations on how we could get the game to work online with what is currently available through unity?

    Thank you!
     
  35. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Hi @giftgamebr,

    a guide on integrating Simple IAP System with Tanks Multiplayer can be found on the documentation pages - here! For integrating with PlayFab, you would follow the guides in the Simple IAP System docs section, specifically this one. As an example, this way you could have a login screen with PlayFab and then load the Tanks Multiplayer Intro scene. I am sorry to say that I am not available for client work and do not have experience with the Photon Tournament SDK.

    ----------

    Hi @Agi356, thanks for your questions!

    If you are using Unity Netcode (UNET/MLAPI), only the host can modify NetworkVariables - I assume you are using NetworkVariables to modify properties like move speed. If that is the case, make sure to implement proper callback methods, so when the host changes the property, the callback is also invoked on the client and can be replicated there. If you are not using NetworkVariables i.e. the speed variable is not networked, you could have the host send a RPC to all players, but only apply the speed change on the corresponding player object.

    It is a bit difficult to provide a solution on why your approach does not work without sample code, but that's basically the two options you have - NetworkVariables or RPCs. The powerups use a very similar approach when they modify the bullet index (selected bullet) on one player, e.g. when picking up a PowerupBulletPower.

    Again assuming you are using Unity Netcode, maybe this forum thread helps? Connecting online already works, except on WebGL, but requires a bit of firewall and router setup. Support for Unity Relay (at the end of the beta), where custom firewall rules would not be necessary, is also on the feature list for a future update.
     
  36. Tweak_Kit_97

    Tweak_Kit_97

    Joined:
    Apr 11, 2021
    Posts:
    2
    Hello Baroni and everyone,

    Your Tank project runs both singleplayer and multiplayer modes in the same project with the same source code without having to separate the code for different modes.

    So I wonder if it makes any slow performance where in the offline mode, networking related stuff is not needed, but still the networking components in the game objects remain actively.

    I see the source code you implemented in a way that could be used for both modes. How awesome that is!

    Looking forward to getting to know your answer soon! Because my team is really struggling in handling the source code for both modes without having to rewrite all of the logic for the online mode since we think we can not utilize the available offline code.

    Thank you very much!
     
  37. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Hi @Tweak_Kit_97, thanks for re-posting here!

    The networking code is indeed needed in the offline mode, for the purpose of only having to maintain one code base for offline and online. The abstraction layer between offline and online is not in the asset's source code, but in the networking plugin - meaning while you might think that networking is involved when looking at the various networking components in the offline mode, the network plugin handles this itself and does not really send any networking requests to the local instance in the first place. But even if it would, since local requests would need to reach localhost, the response time would always be 0 ms.

    You could of course separate the offline and online mode in order to (maybe) save a few milliseconds in processing time, as the networking plugin would then be completely avoided. However, this would be a complete rewrite of all of the source code, effectively maintaining a completely separate project for each mode. This would not be very practical regarding changes and updates, or worth the time.
     
  38. Tweak_Kit_97

    Tweak_Kit_97

    Joined:
    Apr 11, 2021
    Posts:
    2
    Hello Baroni,
    Thank you pretty much for the quick answer!
    I probably have a better vision of the overall approach for the game now.
    Can not thank you enough for always helping us out! Thank you thank you!
     
  39. Moshu

    Moshu

    Joined:
    Mar 13, 2015
    Posts:
    7
    upload_2022-5-21_17-6-51.png

    I get this when I start the game.

    upload_2022-5-21_17-7-50.png

    It hangs here.

    upload_2022-5-21_17-8-35.png
     
  40. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Hi @Moshu, could you please tell the network provider you are using, is this with Unity Netcode?

    If so, what Unity and Netcode version? Could you also please check the TankFree prefab in the Project folder to see if there are missing scripts visible already? Thanks!
     
  41. SilwareStudio

    SilwareStudio

    Joined:
    Oct 28, 2020
    Posts:
    1
    How do I set the camera in the game to a near-tank camera?
    (I Want The Camera To Be Behind The Tank And View It In The Direction It Changes.)
     
  42. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Hi @SilwareStudio,

    please see this post for a similar question on a first person camera:
    https://forum.unity.com/threads/tan...lapi-photon-mirror.410465/page-7#post-7734987

    As written there, the shot position is calculated in a top down view on the screen. Meaning if you simply reposition the camera to somewhere else, the targeting will not work as desired anymore and you will get unexpected results. If you modify the values on the camera script or attach the camera to the turret, you will probably also want to modify the turret rotation behaviour to move it left and right in the forward direction (rather than 360 degrees as it is now).
     
  43. samadqamar755

    samadqamar755

    Joined:
    Jul 9, 2019
    Posts:
    4
    Hi, is there a way to easily switch between two networking solutions? for example can i switch from PUN to mirror easily?
     
  44. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Hi, not really. The networking implementations are very different and come with scripts and prefabs in separate unitypackages. You will not be able to switch between them without overwriting your previous files.
     
  45. Vauxvogh

    Vauxvogh

    Joined:
    Nov 29, 2017
    Posts:
    10
    Hey hey any chance you can update the pun version to Photon Fusion? Its the latest and greatest
     
  46. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Hi @Vauxvogh, thanks for the suggestion and interest! Photon Fusion is not an update though - it is a completely separate asset, replacing all scripts and mechanics of PUN. It's not that simple like updating from PUN1 to PUN2; supporting Photon Fusion requires a complete rewrite, basically as a new networking solution.

    I've had a look at a beta release in the past, however the documentation was really lacking details and the implementation was very unstable. It is still on my research list, but no real release plan yet.
     
  47. jjdomain

    jjdomain

    Joined:
    Sep 11, 2015
    Posts:
    93
    hello, does the asset have local/offline multiplayer functionality? Multiple players play via split screen using same device...if not would it be easy to implement?
     
  48. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Hi @jjdomain! Local split-screen multiplayer functionality is currently not included. Starting from zero, there might be a few difficulties implementing it, but there is nothing specific that prevents adding it yourself. If you get yourself familiar with the asset first, it will get easier to implement by a lot.

    You have to think about how that makes sense though when it comes to user input: on PC, users currently need keyboard & mouse to move and aim, so it would make more sense to support controllers. On mobile, there are devices which do not allow receiving input of more than 2-3 fingers and the screen could be too small for multiple players.
     
  49. jjdomain

    jjdomain

    Joined:
    Sep 11, 2015
    Posts:
    93
    @Baroni thanks for the follow up. My requirements are pretty specific, using an android device (big screen) that allows upto 10 finger touches.
    How would you go about implementing a local multiplayer versus setup?
    For example, if we assume the tank game levels will be loaded in a game scene. So we need to load TWO game scenes side-by-side via split screen, with some tracking of which side/player wins at the end.
     
  50. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    @jjdomain You mentioned "local multiplayer versus setup" but in the context of one vs one playing on the same device, networked multiplayer would not even be necessary at all, it could all run offline.

    You would not load two game scenes but simply have two cameras for the two players in one scene, both occupying half of the screen - one left, one right. Have two input components (one for each player) with the joystick controllers placed on the screen and assigned to the correct player. The game over / win message could then be shown in the middle of the screen, since it is applicable to both players.