When thanking my new patrons at the end I made a mistake and somehow replaced one of the images I made with the thumbnail 😔 Thank you to Thomasz in the Enthusiastic Tier for your support! ⭐️
@tauheedgamedev23884 жыл бұрын
Great tutorial, I'v been using Singletons for a while but with the level of detail in this tutorial I still learned some things. Thanks 👍
@Patricebrouh4 жыл бұрын
Wow, your explanation is so clear. I can say : "Brackeys has gone, thanks to God we have another Brackeys" .
@samyam4 жыл бұрын
I have a long way to go to get to Brackeys level 😄
@marushirudesu2 жыл бұрын
@@samyam you don't have be brackeys, you have to be samyam that can be better than brackeys.
@chris.davidoff4 жыл бұрын
This was really informative! I personally do the persistent scene for different things (Like UI, which I may want to unload in cutscenes and such)
@lemetamax4 жыл бұрын
This is a really awesome video on singletons, I can't believe I've been using it wrongly. I'll have to watch again to understand it tho.
@leonardo66314 жыл бұрын
Great video! Thanks for the nice content ❤️
@syngleton4 жыл бұрын
Sam, this tutorial is incredibly helpful and has completely changed the way I implement this design pattern. The one problem I have with this is I don't know how I'd be able to have a class derive from a base class but also inherit from your Singleton class. The only way I could think of achieving something like this is by turning your Singleton class into an interface, but it doesn't seem like the best approach to me, considering I'd probably have to keep overriding the Awake() and OnDestroy() methods when creating new classes implenting this interface. What would you suggest?
@samyam4 жыл бұрын
Glad you enjoyed it! Hmm maybe you can make a parent empty GameObject as the singleton container for the other game object which derives from that other class? Something like this: Parent.Instance.GetChild()....
@diazpsp11 ай бұрын
What is your font in the VSCode? looks nice
@clc43334 жыл бұрын
aspiring game dev, just at the very beginning stages... couldn't understand this part, so i'll check out some more easier material then come back!
@SubjektDelta2 жыл бұрын
If I wanted to have an object in the scene how could I set it to the instance itself? My problem currently is that I have a manager object in the scene and when some other script tries to use the instance a new one is created.
@ericwoodworth80793 жыл бұрын
ArgumentException: SceneManager.SetActiveScene failed; scene 'Managers' is not loaded and therefore cannot be set active. I've looked over this video many times to make sure I had everything done the same way as you do. My scene is in the build settings properly. Is there something I am missing?
@samyam3 жыл бұрын
Perhaps because the scene is still loading while you are trying to access something. You should wait a frame to make sure it's loaded before accessing the value. You can load it in a coroutine IEnumerator LoadSceneCoroutine(string pSceneName){ yield return SceneManager.LoadSceneAsync(pSceneName); // do something with the scene }
@ericwoodworth80793 жыл бұрын
@@samyam Awesome! Thanks, I am going to give it a shot
@jorgevalles6835 Жыл бұрын
In my job I entered in a nightmare due to Singletons. We reached a point in which literally everything you can imagine was a Singleton ☠. So we started to loose control on initialization and closing of several systems, specially when changing scenes. Lots of things crashing because of requests to singletons that will start working in other scene. :(
@danielbezerra56503 жыл бұрын
Thank you 🙏🏿
@lucky4the4turtle4 жыл бұрын
So uuuh, dumb question, but at 4:48 on line 3 what does do wtih the SinglePatternPersistent class? Edit: Nevermind I should have just kept watching the vid.
@ninqbi1738 Жыл бұрын
i dont understand why you put an "inputManager" obj in Managers scene beforehand. Cause as your scripts, it will generate an T object when we firstly start the game. Can u explain it?. Anyway, this is good tutorial, thks
@fernandomilans84444 жыл бұрын
Hi! could you enable the subtitles? thanks!
@samyam4 жыл бұрын
Hi I'm not sure why it wasn't enabled... For some reason it didn't generate the subtitles automatically. I tried re clicking the language but a video online said it might take some time to show up if it's able to generate it. Sorry ☹️
@candle-likeghost95233 жыл бұрын
Urm.... in 11.03. I need to point out that the "public static T Instance { ...." is not a function but a property. and instead of DontDestroyOnLoad(this), we can do DontDestroyOnLoad(obj), right? (Since Unity destroy the game object with the script when loading, we just need to tell Unity to not destroy the game object when loading).
@samyam3 жыл бұрын
Yes you are correct, however it won't be persistent if no other script calls it's Instance since it will only create the gameobject once it's called. But if you put it in the Awake it is guaranteed to be persistent even if no other script calls it.
@candle-likeghost95233 жыл бұрын
Oh I see, thanks for explaination
@kendrickjba Жыл бұрын
I'm getting this error "ArgumentException: SceneManager.SetActiveScene failed; scene 'Managers' is not loaded and therefore cannot be set active"
@kendrickjba Жыл бұрын
I fix it calling the input manager on start instead of calling it on awake on my player script
@zlisarew6830 Жыл бұрын
I have an issue if I go from scene 1 to scene 2 it will load the Managers scene then if I go back from scene 2 to scene 1 it will load another Mangers scene because Awake() in scene 1, I fixed it by checking if (!Managers.isLoaded) then load Managers scene
@samyam Жыл бұрын
Because it has a Do not Destroy and it keeps it alive during other scene managers. You need to check if there is already another instance running before starting a new one
@arunachalpradesh3992 жыл бұрын
please reply. how can sound manager be as singleton, as everyone says. because singleton gurantees only one class can acess singleton class at a time. what if sound manager contains gun shot sound, which both player and enemy fire at same time. so how can both players and enemy class access singleton at same time.
@WildPork Жыл бұрын
"because singleton gurantees only one class can acess singleton class at a time" this isn't true unless you have used a "lock" to restrict access.
@youcancallmedoggie3 жыл бұрын
Amazing video! helped me a lot, but i have a question, how to stop persistant scenes loading more then once, like when i restart that scene?
@samyam3 жыл бұрын
The singleton will check if an instance already exists and if so not load the extra object. You can make a manager for that persistent scene a singleton.
@vmmi82152 жыл бұрын
I've been travelling through some of your video, i can say that you indeed have a really deep understanding about clean & good code, i hope that you would make a video about things to learn for beginner or intermediate to mastery the code principles such as SOLID principle But anyway, i love your lovely voice 😍👍
@samyam2 жыл бұрын
Thank you so much!! I’m hoping to make tons of tutorials more in the future! :)
@playplus5386 Жыл бұрын
People keep saying that this is a good tutorial, maybe it is, but I'm here to learn the Singleton pattern. However, now I'm confused about the new Unity input system, flags, and many other concepts. Please make a simple scene and focus on the subject: the Singleton pattern. In order to fully understand your tutorials, I have to go back and learn those concepts first, and then come back here. I feel like I'm wasting my time
@LostSol252 жыл бұрын
how long have you been doing game dev? and are you currently working in the industry?
@samyam2 жыл бұрын
Around 6 years! No I'm doing my own stuff :)
@LostSol252 жыл бұрын
@@samyam thats super cool! Thanks and keep going with your tutorials they are amazing!!
@samyam2 жыл бұрын
Thank you! 😄
@SaadTheGlad4 жыл бұрын
Hello! Do you know of a simpler tutorial? I'm just trying to get my references to stay correct after switching scenes but I don't know where to start learning... :(
@samyam4 жыл бұрын
Here’s a tut by Infallible Code on Singletons kzbin.info/www/bejne/o6GwYXZsptqEoNU What’s the issue? Make sure you have DoNotDestroy on your singletons so that it persists through your different scenes. However gameobjects in that new scene still need that reference Class.Instance
@SaadTheGlad4 жыл бұрын
@@samyam Thank you! I have fixed my issue with the dialogue system (parented all the UI elements and the player to a don'tdestroyonload) but a new problem arose: proper level system. I wanted to make one like undertale but there are no tutorials on the subject...
@samyam4 жыл бұрын
Like leveling up? Code Monkey has an in depth video here kzbin.info/www/bejne/oXymfYCsqMx0iJI
@piggeh64654 жыл бұрын
Sam can you do animation movement tutorial for isometric? there's like no videos on the subject :(
@samyam4 жыл бұрын
This video might help kzbin.info/www/bejne/qqrapWyqhNqVe7s But I'll put it on my list for future videos!
@piggeh64654 жыл бұрын
Thanks :)
@CyberAngel673 жыл бұрын
I have to ask, why is a singleton hard to test? Proper written Unit Tests can cover a singleton.
@samyam3 жыл бұрын
If your unit test is self contained and you use dependency injection in your code to avoid strongly coupling your singleton instance with a class then it can work fine. But you have to architect your code in a certain way to achieve this, which many game developers generally do not. See: testing.googleblog.com/2008/05/tott-using-dependancy-injection-to.html
@AndyScott673 жыл бұрын
@@samyam I disagree with that, I have worked in developing Applications with patterns like AOP, DI to name a few. These can all be mocked, and is a major part of doing Unit Tests.
@CCV3343 жыл бұрын
Why unload the current scene and not just load the new scene. If you load a new scene doesn't it just override the current one. The singleton would also have a DontDestroyOnLoad so why would you need to write anything to load it additively?