Watch this before using MLAPI

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
two weeks that's what it took me to create a online multiplayer mlapi ludo game without proper api knowledge why did it take so long uh i went into it really really confident that i would be able to pick up the api on stream and i really look like an idiot for most of the time the reason is because ml api has couple of little twists that you need to know before you jump into it or you're gonna have to discover after a two hour session of debugging this video right here is a must watch if you plan on picking up the email api and you still don't you haven't played with it before you don't know these little quirks that i'm about to mention watch this video completely it's worth it i promise you're gonna save like eight hour of debugging minimum and hopefully by the end you can pick up some useful knowledge uh for working with this api and if you do please leave me a like really appreciate it helps the channel out quite a lot actually the engagement is now the main source of traffic on on youtube so please drop a like subscribe because soon on sunday this week as i'm gonna be doing the live stream i'm gonna be releasing this code for everybody so the code is gonna be on my gitlab it's already on my gitlab but i'm pushing the update with the completed code on sunday eastern and yeah so subscribe remote procedure calls or rpc they're quite handy they allow you to broadcast a function call to one or all the client and you can also call something on the server from a single client so i could say something such as hey i'm a client and i'd like to roll the dice so dice roll server rpc and this code will now be run on the server so this is all server code that will be that is actually being called from a client they even have an example right here in the documentation project the hello world project from the mlapi documentation they have an example of a submit position request which as a client you would call this from the client side this would be run on the server side to reposition your object this was because the server is the one that would move you you're not allowed to move the server is moving you so it's a authoritative server and this would actually move the right value so quite cool now the question is why is my specific rpc flow not doing anything i'm not getting any server let me explain i have a dice roll button this is being called on every single client right so as a client when it's my turn i can press on the dice roll button which would then call the dice roll server rpc and for some reason this code was never run it didn't even enter here if i was to put the debug.log or anything now both of these function both the rpc and also my button both of these are on my game manager object so my game manager object it's right here at the top it's a network behavior and it's a big object that pretty much controls all of the board basically this is all the logic is in this well it turns out that you can only call rpcs on object that you have the ownership of and as a client i do not own my game manager therefore my rpc won't go through so luckily for us there is a parameter we can pass him to make sure that the calls go through even though we are not the owner of the same object so with the required ownership false we can now run this from from any client really and unfortunately for me there is nowhere in the documentation where i can find information about this so nowhere in the client rbc server or pc nothing like that however there was one statement once i actually knew about that uh there is one place where you can find it and it's under the api server rpc attribute is at the very end and you can find here whether or not server or pc should be run if executed by the owner of the object so by default this value is true this value makes it so you can only run an rpc on the same ownership object my second problem was more of a logic issue something that didn't really click in my head initially and it had to do with network transform behavior the network transform is a component that will synchronize your position on both the client and the server it will basically make sure that your object is synchronized to move in the world and everybody else will receive its new position so during the making of the game i wanted every player to own their own pieces so if they were to drop out the pieces would also drop out with them they would disappear but the whole logic behind the board is hidden behind on the server this way the client can't hack the role or their logical position on the board so this means that you cannot change the network position of an object that isn't yours which is totally fine right so you wouldn't be able to move the player one player if you're the player too so you don't want to be able to move somebody else objects however what i found out is that even as a server or a host you cannot move transform either you really have to be the one that owns it so instead i had to call an rpc on the specific client and this one had to move and i've sent him a position so he could update himself then the change would be reflected on all the connected machines so the ludo game has a dice roll which would mean that every time it's somebody's turn they roll the dice and they can get a number in between one and six and i wanted this dice value to be networked so everybody could see what this specific person has rolled for example so if player 1 rolled the 6 i wanted to make sure that everybody saw that he rolled the 6. so i networked this value therefore the value was being propagated to everybody else every time it changed and it worked really well initially so i started hooking the whole flow of my game around that i would wait for somebody to roll the dice and when that person rolled the dice i would fire an event based on the event uh the unchanged event so if my value had changed in the network i would fire an event and then the flow of the game would continue but as i was testing more and more i realized that some of the time the game would get stuck and it would get stuck because i would roll a dice with for example value of three and then it would be the next player turn and then he would roll the dice off the value of three the game would freeze because i basically waited for somebody to roll the dice and then if he rolled the dice i would block him from rolling again and the fact that the first player hit the three the second player hit the three means we have the same value and on the network side if the value is the same even though you say dot value is equal to three it won't change because the value hasn't changed therefore it won't fire an event to everybody and since it didn't fire that event everything got stuck and it just like if you roll the same thing as the last player the whole game would freeze well not phrase but yeah you can't proceed so to get around this if you want to force a refresh on all the machine which maybe is not the best approach but in this very specific case i think it's a good approach even if it's the same value that was in the previous network variable what you can do is you can call the set dirty and put that to true just to make sure you have this behavior being triggered and by doing so you will have the on change event being fired to everybody so the turns in ludo they are clockwise you go from one two three four player id one two three four however if player for example if player three wins then in that game you have runner ups which would mean that the game keeps being played by the remaining players which would instead turn the game into turn one two and four you would skip the number three because that one has finish and he doesn't need to play anymore he's already number one but what got really confusing to me is that the values weren't one two and four they were instead zero two and four and that is because the host is not id one the host is actually heidi zero and then you will skip one id that's where the player one would have been normally but then you skip that id and then you go straight to id2 so your list of connected client in mlapi goes from 0 2 3 4 5 6 and as many players as you wish however you can have a player 1 if there is no host if there's just a server so if you are running a dedicated server that server will be id0 and then the first player to join will be id one if you host meaning that you will be both a server and a client you completely skip the id one which means in my case here i have to create a circular list and add the id 0 if the person was host or add the id 1 if it's a dedicated server now the fifth and final tip for the ml api is actually the blue button just beneath this video if you hit it you actually get more tips video you get more coverage on what i'm doing with this and it's it's a good value it's cheap it's actually quite free and if you if you hit it you get more tips so this one is really easy yeah go ahead and hit that i appreciate all of you and i will see you very very soon with more content and i'll see you also on sunday where i release this code and where we just polish the game make it look good do something with that before we wrap it up alright guys thank you so much see you soon
Info
Channel: Epitome
Views: 20,547
Rating: undefined out of 5
Keywords: MLAPI, llapi, unity llapi, unity mlapi, mlapi demo, mlapi tutorial, multiplayer mlapi, unity multiplayer tutorial, learn multiplayer, learn mlapi, learn unity multiplayer, unity, unity3d, unity multiplayer, mlapi tip, mlapi how to, mlapi relay, mlapi unity, mlapi dedicated server, mlapi
Id: 6d1X3LHxiZs
Channel Id: undefined
Length: 9min 32sec (572 seconds)
Published: Tue May 18 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.