Game Manager - Controlling the flow of your game [Unity Tutorial]

Disclaimer: Game Managers are good for simple games only. For more advanced games, look towards a finite state machine or something similar.
Controlling the flow and state of your game is a fundamental step of game development. I'll show you how to structure your game logic to easily flow between each state (ie: player turn, enemy turn, victory, etc) and share a few tips along the way.
❤️ Become a Tarobro on Patreon: / tarodev
=========
🔔 SUBSCRIBE: bit.ly/3eqG1Z6
🗨️ DISCORD: / discord
✅ MORE TUTORIALS: / tarodev
About Tarodev:
Develop video games like a pro!
Whether you're a beginner or a seasoned game developer, you'll find lots of useful tips and tricks to boost your development career. Visit the channel: / @tarodev

Пікірлер: 196

  • @Tarodev
    @Tarodev2 жыл бұрын

    Game managers are a vital part of any game. If you enjoyed the video, let me know so I can continue making helpful content :)

  • @matthewmathis62

    @matthewmathis62

    2 жыл бұрын

    Taro, I just wanted to say thank you for making these tutorials, which are very valuable, are worth a lot to us, and I know take a lot of planning and effort on your part! Also, I wanted to tell you that you did an excellent job of explaining what you are thinking, and helping us to understand what you're doing in the code. I actually sat in front of the code at around 3:45, and I noticed that I understand the stuff you're writing a lot better than I think I understood tutorial code in other tutorials I have watched. So thank you! I hope you are very successful, and that the things in your life turn out to be much better than you thought they would. Thanks Taro,

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    @@matthewmathis62 lovely words. Thank you so much Matt

  • @ricardomiranda7737

    @ricardomiranda7737

    Жыл бұрын

    This is what I'm looking for, this stuff is hard to find. Where else can I learn to implement this. This is not intuitive and need sets and reps...

  • @omerfarukcin3978

    @omerfarukcin3978

    Жыл бұрын

    I also want to say thank you, I enjoyed watching demo game, your explanation and also quality of your code. It was an enjoyable video from start to finish.

  • @troyna77

    @troyna77

    Жыл бұрын

    how would you implement an "initiative" stat for each player and enemy? so instead of always repeating 1) the player then 2) the enemy, you would have the player and enemy "roll" a die and the highest roll would go first for that round.

  • @jcd9456
    @jcd94562 жыл бұрын

    I've come to this video for no less than 4x already, trying to fully comprehend your video (even downloaded it to free myself from the limits of my interenet connectivity). It looks really really easy, maybe because you have explained it well. Great video!

  • @ABC-cr9mi
    @ABC-cr9mi2 жыл бұрын

    Man I love you! I cannot thank you enough, I had my turn based game using if statements in the update method and using bools to check if the players took their turn and overcomplicating the code. Using states simplified things for me a lot, and my code runs only when the state changes instead of all the time checking if something changed.

  • @LowLevelLemmy
    @LowLevelLemmy Жыл бұрын

    you have the best looking scenes i've ever seen out of all unity tutorial tubers

  • @Tarodev

    @Tarodev

    Жыл бұрын

    Thanks Lemmy 😳

  • @TheeKennyMcB
    @TheeKennyMcB Жыл бұрын

    Great video! I've recently stumbled upon your content while on my Scripting Unity journey. Quickly I'm becoming obsessed with Architecture and managing the flow of the Game and Logic. This and many of your videos are great reference!

  • @Gregasaurus
    @Gregasaurus Жыл бұрын

    Awesome tutorial. Very clear, and I've implemented something along these lines. Keep up the great vids

  • @petrdymanus9073
    @petrdymanus90734 ай бұрын

    Best piece of advice for making a Game Manager I've seen so far. Thank you

  • @ToriloOo
    @ToriloOo2 жыл бұрын

    not 5 minutes in and already learned a ton, thanks for everyting.

  • @rob3rtsayshi
    @rob3rtsayshi Жыл бұрын

    absolutely love your content. love the technical perspective as this is always what i was lacking. so glad i stumbled upon your channel!!

  • @alexstankovic2947
    @alexstankovic29472 жыл бұрын

    I would really like to see more tuts about managers and controllers and their corellation, since i'm going trough a C# cookbook for Unity and it is helping me to grasp about game architecture and Unity and C# in general. Btw, thanks, this stuff is awsome.

  • @christopherneedham9584
    @christopherneedham95845 ай бұрын

    Thanks for these Tutorials, I just found them the other day and am using them to finally develop my game. I joined your discord as well.

  • @slowvibes9595
    @slowvibes9595 Жыл бұрын

    Hey man, first of all thanks a lot for this! As im working on my game I just run into this thingy. You explained it very clearly.

  • @3DLearningBlog
    @3DLearningBlog2 жыл бұрын

    Free GameManager in 10 mins. You earned a like and subscribe. No questions ask.

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    Welcome aboard

  • @sasquatchbgames
    @sasquatchbgames2 жыл бұрын

    love your stuff, thanks so much!!

  • @nugab
    @nugab2 жыл бұрын

    extremely useful content!! thanks for the detailed explanations

  • @vayctorkeesh5393
    @vayctorkeesh53932 жыл бұрын

    Thank you, very intuitive & clear !

  • @RobertGercia
    @RobertGercia Жыл бұрын

    Brilliant tutorial. Thanks for your work!

  • @Bionicbug
    @Bionicbug9 ай бұрын

    Thanks for this tutorial! I am learning how to make my own games now, and this helps!

  • @pj-wille
    @pj-wille2 жыл бұрын

    learned a lot from this video thank you!

  • @SpicyMelonYT
    @SpicyMelonYT2 жыл бұрын

    Ohhh I have always avoided naming it "GameManager" cause I thought that unity put the cog there cause unity already has some script named "GameManager" and I was about to override it.

  • @NachitenRemix

    @NachitenRemix

    Жыл бұрын

    Same

  • @normandybeachparty

    @normandybeachparty

    Жыл бұрын

    Yuuup

  • @bigedwerd

    @bigedwerd

    10 ай бұрын

    Same!

  • @1nfern088
    @1nfern0882 жыл бұрын

    Great tutorial, many thanks good sir!

  • @chichipio2
    @chichipio27 ай бұрын

    Awesome tutorial! Thanks!

  • @JohnK68
    @JohnK68 Жыл бұрын

    The video generates more questions than answers. The overall presentation is nothing to complain about and quite good except for the banging sound on your keyboard.

  • @ravd123
    @ravd123 Жыл бұрын

    Perfect just what I was looking just implementing it. Also great to learn a few other things on the way :).

  • @bannanachef1091
    @bannanachef10913 жыл бұрын

    Amazing video, love your content

  • @nateheney8883
    @nateheney8883 Жыл бұрын

    Really helpful, Thanks man

  • @rambertoeco8930
    @rambertoeco89302 жыл бұрын

    Another great one, thanks!

  • @GUYX10
    @GUYX10 Жыл бұрын

    awesome tutorial! i learned a lot. thank you♥

  • @John-vi8oi
    @John-vi8oi Жыл бұрын

    Why did you call functions like color select outside the manager using OnGameStateChanged, but then calling functions like HandleEnemyTurn() within the manager? I mean, the HandleColorSelection function is empty but its logic handled in another class?

  • @nowlog502
    @nowlog5022 жыл бұрын

    greatest tutorials on youtube i would say

  • @Bemiscript
    @Bemiscript Жыл бұрын

    thx man i rlly needed this

  • @davidarayacadiz7675
    @davidarayacadiz76752 жыл бұрын

    Really good tutorial :)

  • @villagerjj
    @villagerjj4 күн бұрын

    epic tutorial! thanks :)

  • @maiksmith9855
    @maiksmith98552 жыл бұрын

    learned a lot from this video thanks!

  • @biggs6466
    @biggs6466 Жыл бұрын

    Hey man, this was hugely beneficial for me, thank you. If you don't mind me asking, do you recommend any additional resources (books, videos, etc) on the fundamentals of game development? I've been diving into learning Unity, but this made me realize I'm probably suffering from some serious blindspots in terms of the absolute basics of game design.

  • @Tarodev

    @Tarodev

    Жыл бұрын

    I unfortunately cannot recommend anything. I've always been an in-the-moment learner. By that, I mean looking things up as I need them, as opposed to any kind of structured learning experience. It's not for everybody, though... Most people learn better with a bit of structure.

  • @BaneDestabapillado
    @BaneDestabapillado2 жыл бұрын

    Got into a jam (just knowing py(REALLY BAD IDEA)), all my team knows and use unity, so here i am almost 3 am learning C#, somehow after 3-4hrs accomplish to understand almost everything, also ur video is one of the best videos i have seen about this topic, congrats :)

  • @RayznGames

    @RayznGames

    2 жыл бұрын

    Thats the spirit!!

  • @centenarium

    @centenarium

    2 жыл бұрын

    How did it go?

  • @BaneDestabapillado

    @BaneDestabapillado

    2 жыл бұрын

    @@centenarium actually really well, we have one of the best games in the Jam, and was a really fun experience

  • @rangiza6478
    @rangiza64782 жыл бұрын

    simple video, i like!

  • @kyleme9697
    @kyleme96972 жыл бұрын

    This was great, I wish I had seen this video when you made it ... oh well I'm right the track. :)

  • @HYPERMUSH64
    @HYPERMUSH642 жыл бұрын

    Sent here from Create a Grid pt 2, nice connection of tutorials!

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    I don't link my tutorials very often, I should do it more!

  • @AaronAsherRandall
    @AaronAsherRandall Жыл бұрын

    Hey Tarodev, I wanted to thank you for this video! I’m using this to write out the skeleton for an online turn-based combat game I’m building with PlayFab and Photon. I was curious, what UI asset are you using? I love the colors and the font style! So good for prototyping!

  • @TheZamirOrion
    @TheZamirOrion Жыл бұрын

    Great tutorial! It connected many concepts I’ve seen in the past and made it clearer. Question about the implementation of the enemy turn. You use task.delay saying it is not great implementation. Could you explain more? Would you use Coroutines instead in a real world context? Thanks again

  • @hammakechiche7858
    @hammakechiche7858 Жыл бұрын

    Thank you.

  • @user-xp5lv5zc5n
    @user-xp5lv5zc5n Жыл бұрын

    Hi Taro, love your videos. Could you tell me what programs/resources you frequently use for your visual design? I really like the look.

  • @midniteoilsoftware
    @midniteoilsoftware3 жыл бұрын

    Nice tutorial. I’d like to see some videos demonstrating using scriptable objects for this sort of thing.

  • @Kalahee

    @Kalahee

    2 жыл бұрын

    Could you be more precise about what you expect ScriptableObject to do in "this sort of thing"? I do understand that you can plug SO in a state machine, but I'm not sure why you'd want that here, except maybe to subdivide your code, but you don't exactly need SO for that. Only way I can see this is create an abstract SO to inherit from and override "StateEntry", "StateRun", "StateExit" functions. Use some static variable that most of your states need to regularly inspect (reference to stat controllers, player controller, or something). Other than that, have state dependant variables public that you wanna set in the inspector, which is the only reason I see SO used in "this sort of thing", or maybe for difficulty settings then you'd swap "CombatState_Normal" with "CombatState_Easy" or "CombatState_Hard". In the GameManager, have UpdateGameState(newState) call on current state StateExit and new state StateEntry. If current and new state are same, call StateRun.

  • @gregbradburn

    @gregbradburn

    2 жыл бұрын

    @@Kalahee Thanks for the reply. I was just starting to dig into ScriptableObjects and it just seemed like something they'd be suitable for. But honestly, it was so long ago I can't remember specifically why I asked that :)

  • @codyharryman10
    @codyharryman102 жыл бұрын

    Great video as always. Any idea why I'm not able to call the UpdateGameState(); function from a UI Button OnClick() event?

  • @gautamjain6122
    @gautamjain61222 жыл бұрын

    Hi, can you explain why you used static event instead, what happens if you don't use static events here?

  • @AyadoooKK
    @AyadoooKK11 ай бұрын

    12:05 Just a note it wasn't mentioned in the video, Added UpdateGameState(GameState.Decide); at the end of the HandleEnemyTurn ()

  • @koenfrontatie
    @koenfrontatie Жыл бұрын

    Could you explain your thinking behind naming your events? I don't quite understand the conventions. I kind of get the OnGameStateChanged name but what's the reasoning behind GameManagerOnOnGameStateChanged?

  • @markcheng4604
    @markcheng4604 Жыл бұрын

    Amazing video! Just wondering how you were able to create the alt + Enter to generate the switch statements at 3:03? Would love to know!

  • @Tarodev

    @Tarodev

    Жыл бұрын

    That was my bad. I was using an extension called ReSharper. Provides a bunch of quality of life improvements. Rider does the same

  • @markcheng4604

    @markcheng4604

    Жыл бұрын

    Thanks that’s a convenient extension to know 👍

  • @nikokune1395
    @nikokune1395 Жыл бұрын

    "This is not the best way to do it..", "that is not good design.." ... ".. but for the sake of the tutorial".. The idea is clear already after the first event handling, it would be great to see how every part of the code in the gameManager you write is THE GOOD WAY to do

  • @mehmedcavas3069
    @mehmedcavas30692 жыл бұрын

    I used the gamemanager exactly the same way like here in the past

  • @michaelrobens9958
    @michaelrobens9958 Жыл бұрын

    Excellent tutorial, thankyou. Can I get the source to the Unit.cs mentioned which uses Factions? Is it available via your Tarobro membership? I'd also appreciate a tutorial on Unity Factions.

  • @Tarodev

    @Tarodev

    Жыл бұрын

    Hey mate, I actually don't have the source for this video. But if you pop into discord I can help you with whatever you need :)

  • @quantran9219
    @quantran92192 жыл бұрын

    tks u

  • @felipejhony6039
    @felipejhony60393 ай бұрын

    How to make those slick buttons? So pretty!! I want those!

  • @yaroslavmakarov2218
    @yaroslavmakarov2218 Жыл бұрын

    Спасибо

  • @owencoopersfx
    @owencoopersfx2 жыл бұрын

    That shortcut at 3:00 to auto-generate the switch container just blew my mind. Huge time saver.

  • @antoinemaes

    @antoinemaes

    2 жыл бұрын

    Any idea why it would not work here? Windows + latest editors... Some settings need to be activated somewhere?

  • @KJAndroidGames

    @KJAndroidGames

    2 жыл бұрын

    @@antoinemaes There is also other way to do it: you can type switch and then press Tab twice. Then write the enum.

  • @Hamentsios10
    @Hamentsios102 жыл бұрын

    I still don't get how gameobjects can speak to other object codes. There are built in methods like oncollision and stuff that wait for events and return data, but i dont get how i can communicate between game objects and share information.

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    I just recently made a video on all the ways objects can communicate. Here it is: kzread.info/dash/bejne/lqiqmc-jmsLPn8o.html

  • @troyna77
    @troyna77 Жыл бұрын

    how would you implement an "initiative" stat for each player and enemy? so instead of always repeating 1) the player then 2) the enemy, you would have the player and enemy "roll" a die and the highest roll would go first for that round.

  • @halivudestevez2
    @halivudestevez2 Жыл бұрын

    I am inspirated.

  • @vaibhavjaiswal799
    @vaibhavjaiswal7992 жыл бұрын

    Can you tell how you made your shader

  • @tylergillette7050
    @tylergillette70502 жыл бұрын

    (Sorry ahead of time for the long comment and lots of questions, I segmented them out with numbers highlighting key areas) I'm learning about GameManagers right now and this seems like a really useful tutorial, thanks! But, just out of curiosity, (1) what would the implications be to handle all of these features yourself, using things like variables/properties inside of a GameManager proxy script? For example, setting a public property or field string as the state name, inside of your GameManager proxy script, to "BetweenRounds", then your game objects/scripts check whether or not the state of that public property/field is "BetweenRounds" before doing the performing that code? The reason I ask is I'm much more familiar with that sort of workflow, and if that's something I can do, and it's not unreasonably impactful on the performance, then, (2) is that an acceptable solution? If it's not, and there does happen to be a downfall or disadvantage, then I would have to put my laziness aside and do it properly. Another reason I ask is, the concept of a GameManager seems like a no-brainer when handling multiple elements, but when I looked into it online, I find all sorts of conflicting information, some regarding why Singletons are bad to use in Unity, some how Singletons are good to use in Unity; And one specifically, a Unity help article from 2017 stating how the GameManager workflow is "Incredibly out-of-date", linking to another article that seems to suggest you should use a preload scene instead, somehow. Although, admittedly I didn't read through it in entirety yet, I've attached it below if you're curious: answers.unity.com/questions/1124691/creating-a-proper-game-manager.html ((3) It would be nice to hear what your opinion is on that, because if I try to implement an out-of-date workflow then I might end up running into incompatibilities with future features, or dropped support of that workflow)

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    I read the post you linked regarding a prescene and I think you may be a bit confused, probably due to naming. So when he's talking about game manager, he's more referring to a full system wide management solution, including sound, scenes etc etc. This video is a manager to control the flow of the actual game and has no overlap to his guide. You would absolutely not want to put this on an object which persists through every scene including menus and the like, you'd want a brand new instance of it each new game. Singletons are very handy and are used widely not just in unity but across all of c# development. Even though his post has no overlap with my video, I'd still like to put my two cents in: Firstly, I hated how he wrote it in such a factual way when it is in fact subjective. Saying that, a single DontDestroyOnLoad created in a _prescene could be beneficial for readability, but honestly doesn't make too much of an impact. The fact he didn't actually make static instances of the systems classes but instead expected the dev to find them by searching the scenes and then setting individual references in every class which needed them shows me somebody told him statics/singletons are bad so he's just avoided them for the sake of doing so. In the end programming has many conventions, but as long as an implementation isn't detrimental to performance or readability, you should follow the design pattern you or your team enjoys.

  • @tylergillette7050

    @tylergillette7050

    2 жыл бұрын

    @@Tarodev Thank you very much for your response! I just found you tonight looking for information on game managers, and I also asked a few devs in a discord group, so I got some more advice, it's all helpful. And, I'm glad I found your channel, severely underrated, you have a ton of content that I can already tell is going to be useful in my process, keep up the great work!

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    @@tylergillette7050 Glad to have you on board.

  • @codenameumoja8995
    @codenameumoja89953 жыл бұрын

    Why don't you do a tutorial that builds the scene with the firing etc.

  • @thundethunder1
    @thundethunder1 Жыл бұрын

    Taro, in MenuManager you added a serialized button for _attackButton. What would you do in case of multiple buttons? For example more than 8 buttons.

  • @kirukanya

    @kirukanya

    9 ай бұрын

    I would guess make an array/list of buttons!

  • @leoniesart9588
    @leoniesart95882 жыл бұрын

    Thank you so much for this video!:) I was able to follow until 5:30 than I got Error CS0246:The type or namespace name 'GameState' could not be found (are you missing a using directive or an assembly reference?) from Unity. Do you have any tip for me how to tell the MenuManager what a GameState is?

  • @ppapuli9009

    @ppapuli9009

    2 жыл бұрын

    Is GameState public?

  • @drtrouser

    @drtrouser

    2 жыл бұрын

    because he declares it outside the class

  • @speedy1000ism
    @speedy1000ism Жыл бұрын

    Hey Tarodev, Why are you not using a Singleton here? Can you explain the difference between a singleton and this method?

  • @Tarodev

    @Tarodev

    Жыл бұрын

    This method means when the scene is transitioned away from, this game manager will remain idle, in memory. Once a new game scene is spawned, a new game manager will override the last one. This means we don't need to write any reset logic 😊

  • @Caden_Burleson
    @Caden_Burleson Жыл бұрын

    What do I have to enable to get that alt+enter key command? Does it work in VSCode?

  • @tylerdean2973
    @tylerdean29732 жыл бұрын

    How closely tied is the GameManager to the EventSystem? Does one take the place of the other? Or do they fulfill separate roles?

  • @DarkzarichV2

    @DarkzarichV2

    2 жыл бұрын

    They can both exist at the same time just that with the event system you can avoid having static game manager at all since you could just not access it directly but still you'd have a place for your game state

  • @amatorii55
    @amatorii55 Жыл бұрын

    It’s better to have states as individual objects of a state class. This is so you can have the state objects handle logic that’s only relevant to them, meaning your code is much easier to expand, bug fix and read. If you don’t know what I’m talking about or mean, google search OOP C#.

  • @Entikai

    @Entikai

    11 ай бұрын

    You are talking about the State pattern. He said in another video that handling states with a switch is good for 90% of indie games. But state pattern is not harder then this version in my opinion. I wish Unity had some native built in tools for making states.

  • @louxie6367
    @louxie63672 жыл бұрын

    When you subscribe/unsubscribe to the event would it be better to use onEnable/onDisble? Saw it in some other video, and was wondering if which of the methods would be best practice?

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    It's contextual. In this case it would serve the exact same purpose. If I HAD to choose one or the other, I'd choose enable/disable.

  • @louxie6367

    @louxie6367

    2 жыл бұрын

    @@Tarodev Thank you so much for the quick reply! (and also your video was great help) 👍

  • @SanderDecleer
    @SanderDecleer2 жыл бұрын

    Hey, I've been watching a lot of your tutorials these last few days and I find your content entertaining and to the point. I do have some questions concerning this video. You say you keep the complexity low and easy to adapt, yet you need to enter and edit each leaf node in your game flow to change the way the logic plays out. Also, each leaf node needs to know about the existence and implementation of the game manager. Is this something only suitable for prototyping or how would you scale this up? How would you handle your UnitManager and your team color select screen when more options become available or required? Seeing this system handle change (as you demonstrated with the decide state) can really sell its benefits or show its downsides. I would really appreciate your input on these matters as it is something I spend lots of time thinking about myself.

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    Although people tell you left and right that coupling your components is bad, it really isn't. Yes, maybe on a AAA game with lots of people working on it, but as a very small team working on a small to medium sized game it's not a big deal. If you do want to decouple a but more and organise your states with a bit more control, look into a statemanager. I personally avoid them unless absolutely nessersary. It really comes down to personal preference, but I tend to use the easiest and quickest option if there are no major reasons not to.

  • @SanderDecleer

    @SanderDecleer

    2 жыл бұрын

    @@Tarodev Thanks a ton for your reply. I always get the shivers when I have to tightly couple things. I have a junior coder that I do not want to influence in a bad wat. It might just be specific to my company's way of working, with customers and project leads changing their minds a lot all the while I'm trying to maintain a certain consistency within the several applications we are working on and maintaining. I appreciate the added nuance of your reply, it makes it easier to frame the video within its correct context.

  • @RealisiticEdgeMod

    @RealisiticEdgeMod

    2 жыл бұрын

    @Sander Decleer Do yourself a favour and forget everything youve seen in this video. If you have a gamemanager that keeps track of game state then you need an event system to communicate between objects. So thats A LOT more code than just calling methods on classes. The information you pass between the objects must either be stored in each object until the next Update call (so every object that needs to know some information needs to store its own internal copy of it instead of just calling a method on the class and requesting the information) OR you need to store all information passed between objects in the gamemanager as part of the game state. So now you effectively have one giant class containing all these GLOBAL variables.

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    @@RealisiticEdgeMod I'm assuming you over-engineer everything. For small to medium games, this pattern is just fine. In fact most shipped games would be using this pattern. To say ignore it entirely just because there is a more complex and scalable solution is silly. Use the quickest and most efficient tool for the job at hand.

  • @SanderDecleer

    @SanderDecleer

    2 жыл бұрын

    @@RealisiticEdgeMod Thanks for your reply. I see the advantage of totally decoupling everything and using a message system once you application grows larger. For a smaller system or subsystem I believe readability and ease of seeing all moving parts in a sequential fashion has its merits. So there direct message calls could be an option. The thing I disagreed most with in this video would be that the state change is controlled by the simpler classes, thus making them dependent on the implementation of the gamemanager. The core application logic should be contained there, and other objects should only expose events or another way for the game manager to determine what happened and act accordingly. Event systems are one option for that. Excuse the rant, I appreciate your time and insight.

  • @justtekina6709
    @justtekina6709 Жыл бұрын

    I'm trying to figure out how to create persistent based game that runs in the background

  • @n_mckean
    @n_mckean8 ай бұрын

    Forgive a possibly stupid question, but in a turn based game across different devices, are the states framed purely within the perspective of the device of the player in question (e.g. Your Turn, Wait, Your Turn, Wait, Win/Lose) or would it consider both players (e.g. Your Turn, their Turn, Your Turn, Their Turn, Win/Loss). My assumption is the first based simply on the fact that one device would see a Win screen and the other a Loss screen, so for this along they'd be "blind" to each other, other than updating the gameboard status after the other player has made their move.

  • @AlexjW3
    @AlexjW32 жыл бұрын

    How would I check the current state during the update method? I understand that the GameManagerOnGameStateChanged function only triggers when the state is changed, there are other functions I'd like to trigger during update only if the state is the correct one.

  • @AlexjW3

    @AlexjW3

    2 жыл бұрын

    Solved: if(GameManager.Instance.State == GameState.StateName){}

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    @@AlexjW3 you got it 😉

  • @muffafaYoutube
    @muffafaYoutube2 жыл бұрын

    Which extension do you use that has a hammer icon? the icon next to numbers that refer to which line you are?

  • @Zicore47

    @Zicore47

    2 жыл бұрын

    This is probably ReSharper.

  • @muffafaYoutube

    @muffafaYoutube

    2 жыл бұрын

    @@Zicore47 thank you

  • @darkdoom907
    @darkdoom907 Жыл бұрын

    what is that shader on your materials?

  • @NHGeneral
    @NHGeneral3 жыл бұрын

    Hello Tarodev, I have a pause/unpause function, should we add them to the game state manager?

  • @Tarodev

    @Tarodev

    3 жыл бұрын

    This is a design decision I've gone either way with. In most cases I'd say no. It comes down to a lot of things like if you're setting your time scale to 0, if it's going to be difficult to re-trigger the unpaused state without causing double up, etc.

  • @NHGeneral

    @NHGeneral

    3 жыл бұрын

    @@Tarodev thank you, just as you said.

  • @zachdavis6624
    @zachdavis66242 жыл бұрын

    Alt Enter not working to auto fill the switch statement for me...

  • @frankiwinnie5180
    @frankiwinnie5180 Жыл бұрын

    Hello nice tutorial. I have a question though. I want to make: when I press the button the attack function will be executed the turn after the button has been pressed. So if I press button on turn 1, the function will be called on turn 2. Is it possible? Hpw can we store the turn integer? with an enum?

  • @Tarodev

    @Tarodev

    Жыл бұрын

    Sounds like the button should execute the change state and in the state change event you should execute your attack

  • @frankiwinnie5180

    @frankiwinnie5180

    Жыл бұрын

    @@Tarodev Thanks that was inspiring

  • @YangSunWoo
    @YangSunWoo2 жыл бұрын

    Learning Unity feels like I'm learning React again.

  • @barbarosatmaca3318

    @barbarosatmaca3318

    Жыл бұрын

    Bruh this is not about unity. It's a design principle

  • @DarthMerlin
    @DarthMerlin2 жыл бұрын

    I noticed you used Awake() and OnDestroy() to subscribe and unsubscribe events. Most other tutorials I've seen on the subject use OnEnable() and OnDisable() for this. Is this just a matter of preference, or is there a reason to use one function over another?

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    Unless your object is being enabled and disabled dynamically it doesn't matter in the slightest as it'll do the same thing. If you don't have enable/disable logic I'd say use Awake/Destroy as they're the first very and last lifecycle events to be called.

  • @DarthMerlin

    @DarthMerlin

    2 жыл бұрын

    @@Tarodev Cool, thanks.

  • @phamohuutaib2-29-9
    @phamohuutaib2-29-92 жыл бұрын

    bro, i want an app to speed up the game but i don't know how to do it

  • @cheeseriners
    @cheeseriners2 жыл бұрын

    I was interested in this (had heard about this approach, but never implemented it myself), but when you made the UnitManager change the state of the game, it gave me pause. Is there a relatively simple way to avoid this? I'm think events or something like that. So the actual state changing happens inside the GameManager, and it just listens things happening in the game before changing. It starts getting really close to a state machine by then, but still. Opinions?

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    Just depends how decoupled you'd like to make it. Don't just decouple for the sake of it, do it when you feel it's needed. For example if you think the project will chop and change a lot, or if you think you'll ever need each individual part by itself (for testing, or different scenes). Decoupling has many benefits, but it also makes it harder to keep track of what's happening. My main rule: keep it simple unless required otherwise.

  • @ellmatic
    @ellmatic2 жыл бұрын

    Apologies if it's already been asked, but why is the GameState enum declared outside of the GameManager class?

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    Just so when referencing the enum outside of the Game Manager class we don't have to do GameManager.GameState.State, we can just do GameState.State. No other reason 😊

  • @ellmatic

    @ellmatic

    2 жыл бұрын

    @@Tarodev Makes sense, thank you! Great tutorial!

  • @hernandeztorresederjairdej5564
    @hernandeztorresederjairdej55642 жыл бұрын

    Could you explain alternatives to avoid hard coding?

  • @AM-vr4qy

    @AM-vr4qy

    2 жыл бұрын

    Create a publisher subscriber system - an eventbus that manages the subscribing to and publishing of events.

  • @miwwie1504
    @miwwie1504 Жыл бұрын

    Question: Aren't we supposed to avoid using singletons? According to others, you can go without using them, and there are better options, but I don't know which ones. I don't know what to avoid using singletons for, either. What do?

  • @Tarodev

    @Tarodev

    Жыл бұрын

    People love to hate singletons. It's the cool thing to do in the unity world. You can ask those people for a personal example they have come across where singletons were bad, but they won't be able to give you one. The main concern is that it can become messy in a large project, but I've created large projects and they are entirely manageable. I also use SO-Architecture, which is generally what people replace singletons with. I love it, but would say it gets equally messy on large projects. Singletons are 100% fine and are the quickest way to implement game-wide code access. Until you come across a major problem with them personally, don't listen to the deniers.

  • @miwwie1504

    @miwwie1504

    Жыл бұрын

    @@Tarodev i see, I've been trying to learn this today and it takes a while to fully understand how it all works and how to implement it the best way. But I'm glad you responded, and I'm glad i found your channel, it's great for learning about stuff i never find anywhere else. Thank you darling 💞

  • @Tarodev

    @Tarodev

    Жыл бұрын

    @@miwwie1504 enjoy your learning adventures

  • @miwwie1504

    @miwwie1504

    Жыл бұрын

    @@Tarodev thank you!

  • @sethdossett1304
    @sethdossett13042 жыл бұрын

    at 5:50 what is the difference in using OnEnable and On Disable methods to subscribe and unsubscribe the event? this only way ive done it and ive not used OnDestroy?

  • @BenVanTreese

    @BenVanTreese

    2 жыл бұрын

    The main difference is that onawake/ondestroy is for the object lifecycle, vs onenable/disable can be called if the behaviour is enabled/disabled. Both will be done when object is started/destroyed. This explains it docs.unity3d.com/Manual/ExecutionOrder.html

  • @kennysrael2288
    @kennysrael22882 жыл бұрын

    What is the benefit of marking the Action as an event?

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    It's more of a limitation. It prevents external classes from assigning it, they can now only subscribe to it.

  • @lifemetatv5094
    @lifemetatv50942 жыл бұрын

    So does a game manager replace a game loop?

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    By game loop do you mean void Update? If so, no at all. If by game loop you mean a place to manage the flow of the game, for example initial setup, player turn, enemy turn, deciding if the game is won/lost, than yes. Think of GameManager as an orchestrator. It's the only place to further the game to the next step. (by game I mean actual gameplay, not main menu, splash screen etc).

  • @oidelima
    @oidelima2 жыл бұрын

    It looks like ChangeState is being called recursively so that the OnGameStateChanged?.Invoke() commands will run in the opposite order. Wouldn't this cause some issues?

  • @oidelima

    @oidelima

    2 жыл бұрын

    Also, how would you change this to not use the aync?

  • @boogiewg5141

    @boogiewg5141

    Жыл бұрын

    It is causing problems, any solution to this? (When changing to a new state inside the funciton called by the switch)

  • @Shonia
    @Shonia2 жыл бұрын

    Can we subscribe lambda function to the event and then unsubscribe that lambda. SomeEvent += () => print("Something"); SomeEvent -= () => print("Something"); is this possible?

  • @Tuligarnio

    @Tuligarnio

    2 жыл бұрын

    I guess it's too late but for lambda expressions you can only subscribe (because as there's no reference you can't unsubscribe it).

  • @zekiozdemir420
    @zekiozdemir4202 жыл бұрын

    So, is it okay to use gamemanager as singelton?

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    If you work with a team including designers, look into decoupled architecture. If you're working solo or with one other, singletons will simplify your code and speed your development. Don't listen to people who say they're bad 100% of the time. Everything has its place

  • @orwell235
    @orwell2352 жыл бұрын

    Making a GameManager and events static is an architecture killer, this is no doubt. Other than that good tutorial, keep it up!

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    I agree, for large projects. But a small one? Use the quickest tool for the job which is undoubtably singletons and enum based game managers. Saying that, I have used both of those things in decently sized projects (albeit, as a solo dev) and they've been fine

  • @orwell235

    @orwell235

    2 жыл бұрын

    @@Tarodev For the sake of the tutorial it might be the case but I did not expect to see a static GameManager in the video called "Game Manager - Controlling the flow of your game [Unity Tutorial]" since it is definitely not the best practice. Long story short, it destroys OOP concepts completely, GameManager stops being an "entry point" and it is hard to control on a larger scale since everybody calls it from everywhere. Besides that in our production we avoid using UnityEvents. I understand it was made for the sake of simplicity as well (just drag and drop) and it might be useful if designers tweak them (which never happened to me in real projects). In any case, I love your channel and there is a lot I have learned from you.

  • @serhan477

    @serhan477

    Жыл бұрын

    @@Tarodev What will be the problem of using this static GameManager in a large project and is there a better solution?

  • @perrygretton474
    @perrygretton4742 жыл бұрын

    Hi, Tarodev, that's a great tutorial. I learned a lot from it. I was wondering if you have the code available in downloadable format.

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    Ahhh, I didn't realise I hadn't added it to the description. I'm away right now but I'll try remember to put it in. Sorry about that mate!

  • @perrygretton474

    @perrygretton474

    2 жыл бұрын

    @@Tarodev Much appreciated.

  • @perrygretton474

    @perrygretton474

    2 жыл бұрын

    I'd love to try this out, but I need the code. I mentioned this before and I thought you were going to give us a link. Can you do that please, because this is the best tutorial on this subject.

  • @UlrikxD
    @UlrikxD Жыл бұрын

    giant!

  • @NIKOSPARAPONIARIS
    @NIKOSPARAPONIARIS2 жыл бұрын

    Sad - seems to be such a usefull tutorial.. Also for Begginers like me .. !!! But its an example on a "prefixed Game" that never showed how it works - so that makes it MUCH more complicated for me to understand :( Although Thanx for the Tutorial

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    I see what you're saying and I could have done a little more to simplify it. But the video was not about the game (what you see in the video is the whole game, I made it for this video). Every time I make a tutorial I have to decide if I want to make it visually pleasing and fun to watch or drop-dead boring with no context. I'll keep this in mind though and try to simplify it for new devs. :)

  • @igorov3d331
    @igorov3d3314 ай бұрын

    in kzread.info/dash/bejne/Zn1k2NGnqdSzmZs.html there is apparently a shortcut to implement a new function, when you write it, and its not existing yet, can you tell me how you did it?

  • @igorov3d331
    @igorov3d3313 ай бұрын

    I dont understand that there is logic inside the switch statements, and additionally in other scripts in the game

  • @MaksMikhnevych
    @MaksMikhnevych2 жыл бұрын

    oh yeah, good old "game manager" approach, pretty common, not necessarily good though when it comes to scaling.

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    Game manager should be a pretty simple script which just orchestrates. It shouldn't have any system specific logic, keeping is relatively lean even at large scale. What do you prefer to use for large projects?

  • @AlexjW3

    @AlexjW3

    2 жыл бұрын

    @@Tarodev What are your thoughts on using this design pattern vs. a state machine pattern? I build my project with your system, after reaching a level of complexity I'm thinking about rewriting as a state machine.

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    @@AlexjW3 yup it's a good thing to think about. Personally it's all about the complexity and scale of your project. I've built a tactics game using just this workflow and it was perfectly fine. The good thing about a full state machine is that you can reuse it in a generic way across multiple systems. What I suggest is using the simplest option, unless you know ahead of time it will cause problems. That's basically the philosophy I use across the board.

  • @BlackoutGamingChannel
    @BlackoutGamingChannel2 жыл бұрын

    I learnt absolutely nothing from this video! this was because i wasn't paying attention. *_*note to self. rewind video and pay attention*_*

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    Got me in the first half bro...

  • @BlackoutGamingChannel

    @BlackoutGamingChannel

    2 жыл бұрын

    @@Tarodev sorry lol. I keep getting distracted. Good for your view count though!

  • @xanaramus
    @xanaramus2 жыл бұрын

    Nice tutorial. But i would strongly not recommend making any managers or controllers - they completely break single responsoblitiy principle. The better approach would be to create a state machine not from enums, but with states being classes. This way you encapsulate logic and make clean, resusable code.

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    State machines (I do use them) also come with a bunch of problems. For example unless your states are monobehaviours, your 'Jump' state can't even hold your jump particles, audio, jump height, coyote time, etc etc. You need to store it all on the state manager, along with every other states references. It's like solving one problem, but only half the way... For any small project, I'll use a simple enum game manager as it quick and easy. Making code reusable and easily maintained only matters when it will in fact be maintained. Even then, spending 10 hours making code maintainable to save you 5 minutes updating something in the future is a bad use of time. This is VITALLY true for game devs as we tend to make 20 prototypes before settling on a game to complete.