A tip for devs that haven't found this yet: Edit->Preferences->Scene View->Create Objects at Origin, check it. No more resetting newly created gameobjects!
@oleyb1232 жыл бұрын
😮
@Tarodev2 жыл бұрын
OH wow
@pixeldust22342 жыл бұрын
Alt Shift N also helps!
@DevDunkStudio2 жыл бұрын
Omg thank you
@apubetico2 жыл бұрын
thanks bro
@Soundy7772 жыл бұрын
The only dev channel with a budget set aside for costume! Love it!
@Tarodev2 жыл бұрын
Rocking my Red Rooster hat
@NilsMoller2 жыл бұрын
When you said "If you're really cursed, you actually open the preload scene every time" my heart dropped, as I am doing that. Did not know these options even existed! Thank you sir, for making my life easier once again
@Tarodev2 жыл бұрын
Glad I could help make your life easier :)
@MasterDavicous2 жыл бұрын
I am guilty of this as well 😹Spent a whole year working on my commercial game doing this ahhh. So glad I know about this now!
@Tin_Protopixel2 жыл бұрын
We use this in every project. Your channel is amazing, intermediate to higher level stuff, that is needed for the game dev community. Keep up the awesome work.
@insidiousmaximus2 жыл бұрын
ditto
@FelixGB_ Жыл бұрын
As a newly Unity user / gamedev, I love your vids so much! Learning a lot. Thank!
@nightcode8470 Жыл бұрын
i didn't understand the value of this a year ago..... and now i finally understand the value of this...
@Tarodev Жыл бұрын
Growth :)
@Rovsau2 жыл бұрын
I really like this solution. Out of all the chaos in my head, this brings some serenity. Big thumbs up!
@ottopia2 жыл бұрын
I love how your not afraid to show off your collection of transparent objects in the background.
@Tarodev2 жыл бұрын
Haha
@gamedevtom69142 жыл бұрын
Damn, I'd been using a similar but imperfect system after running into the build index nonsense when running from the editor. That extra snippet of code is going to save me a lot of heartache. Thanks!
@Altair81132 жыл бұрын
As a hypercasual developer, I generally create one scene, then load the levels as prefabs as it is much faster than changing scenes when a level is completed. However, your solution looks better on larger projects. Cheers!
@nullx23682 жыл бұрын
Debateable, even as hyper casual id recommend trying these things. Problem is most mid level developer over use them and make their work complicated. There is a balance, I'll always prefer to code the simplest way, but something like this helps you keep things simple once you do it once.
@youraveragedude87672 жыл бұрын
The reason why prefabs are faster than loading a scene normally is because prefabs are loaded into memory when the project starts meaning they are already loaded they just need to be instantiated while things aren’t loaded into memory.
@youraveragedude87672 жыл бұрын
This is a good solution for small 2D projects which have pixel art but it becomes a huge performance issue on larger scenes and 3D projects
@onatkorucu8422 жыл бұрын
Why don't you use additive scenes instead of prefabs?
@Altair81132 жыл бұрын
@@onatkorucu842 Prefabs are still much faster than additive scenes unfortunately.
@tommallama96632 жыл бұрын
Fairly similar to the approach I've taken in the past both on personal projects and at my jobs. We can't escape all dependencies and I think this approach is fairly straight forward. This has proven especially useful in RPGs or any game that needs the games state at all times for Analytics purposes.
@bunggo99142 жыл бұрын
you are now my favorite game dev tutor
@DePistolero2 жыл бұрын
Great one, thanks, I use dependency injection, a combination of generic interface and a static class( it accepts those searching the dependency and dependency ) so when a dependency is created it goes through the list and injects the dependency to seekers, it creates really nice init flow of the scripts.
@Mickplouffe2 жыл бұрын
Don't apologies for the Quaternions video... For the small part a know about them I am still glad you still alive and not in super deep depression from them!
@abrahambrookes19272 жыл бұрын
bro your whole channel is pure gold
@Tarodev2 жыл бұрын
Thank you brother 🙏
@petrosgiannopoulos1122 жыл бұрын
Having done both the Init Scene method (for default screen resolution settings) and Loading Data from a previous scene to get to the main game while also having a bunch of Managers one under the other, I got to say this will probably be my go to from now on. Super simple and easy to setup. Thank you!
@FingarB Жыл бұрын
Wow, thanks!!! So I have been organizing my stuff with a Bootstrapper-scene and SystemScripts-prefab for over 6 years now...Never knew about the RuntimeInitializationOnLoadMethod-attribute. Guess its time to update my libraries again.
@crowbarska2 жыл бұрын
Across my various projects I've been through all the undesirable ways of doing it that you mentioned. Now I am immediately switching to using this method. SO much better. Thanks for this great tip! 👍
@Destructivepurpose2 жыл бұрын
This video is insanely helpful, you've saved me so much annoyance with flicking back and forth between scenes!
@Tarodev2 жыл бұрын
Happy to serve 😊
@KeyboardKrieger2 жыл бұрын
Fuck it, that's the best solution for this problem I have seen so far. And I'm a bit disappointed I didn't come up with this idea myself xD
@Willyuum2 жыл бұрын
You are on of the greatest youtubers to learn game development from
@xinoHITO2 жыл бұрын
I use the preload scene to handle my managers but load it additively with the InitializeOnLoad. I haven’t got any issues and don’t have to open it every time i hit play. Having said that this is also a great solution!
@__ian94__2 жыл бұрын
Awesome tutorial, I had actually been struggling with this lately so this video came at the right time. Thanks Taro! 🐙
@Zicrus2 жыл бұрын
THANK YOU!!! I have been looking for a way to do this for a very long time, and why tf has literally noone else made a video about this?!?!
@RugbugRedfern2 жыл бұрын
I'm learning so much so fast! Thanks for all these tip videos :D
@GamesForTheWlN2 жыл бұрын
This is very similar to an open-source asset I am developing. The difference is that you inherit from what is called a `SystemBehaviour` which is essentially a MonoBehaviour and when you define that type using reflection it will automatically create that instance on load. An editor window is used for the serialization of those behaviours. And there is a lot more nice kind of API around it. But I like your simple approach for those who want their own solution and something that is quick to do.
@DenatusDotCom2 жыл бұрын
Great video about a subject I've recently researched a bit. This video could have saved me hours! Time wasn't wasted though since I learned a lot of different methods for different sizes and scopes of games. This way is perfect for my short jam games and reusable.
@SamRivello Жыл бұрын
Great tip. Useful for many things. However, in a correct Singleton pattern, each Singleton will create itself (e.g. first call to 'Blah.Instance' will create it)
@r1pfake5212 жыл бұрын
I use a multi scene setup for my "Initial loading" stuff and then load the actual gameplay scene(s) on top, it doesn't have the issues you mention, because with a multi scene setup the "preload" scene will always be "open" and you just drag&drop the other scenes you want to test or edit. But I don't use any static singletons, because in my opinion they are a quick & dirty excuse. There are many better ways to achieve a "connection" between objects.
@MaZyYTube2 жыл бұрын
Yes we do the same way and this in an network game (mmorpg). We achieved but problems like the spawned gameobject will be in wrong (default) scene first. Unity really need to add something like Instantiate(toScene) so the gameobject is not in the wrong scene.
@r1pfake5212 жыл бұрын
@@MaZyYTube There are methods to move the object to a different scene, but yeah it would make sense if you could directly specific the scene in Instantiate
@PitiITNet2 жыл бұрын
Great video! Auto initializing stuff with scripts is definitely the way to! :) I think the only thing I would add is a check if the object is already not there! I am definitely going to start using that from time to time :D.
@codastudiode2 жыл бұрын
Dude! you're videos are in the next level! I love it...
@elvismd2 жыл бұрын
This solution rocks! I'm actually doing this currently for my project, I saw on another devlog video a couple of months ago... Before this I was using multiple scenes to initialize those systems, then I would have like the Systems scene that would load before all the other ones or I'd work with multiple scenes loaded, this is good when you're working on a team of 2, it avoids a lot of errors when merging commits and using GIT........
@elvismd2 жыл бұрын
..... but the downside is that you must always work with multiple scenes opened and sometimes you forget the actual order of loading it, or you are loading something way later than you should, because scene 3 needs somethings that is on scene 2, and scene 2 needs something that is on scene 3 (on the editor this works because it's all loaded but on the final build you have to load in an order) and then you endup having to *REDO* all your code relationships that you assign through inspector fields (because you cant reference stuff from other scenes through the editor). So your solution is way better, but I think a hybrid between multiple scenes (so you and your partner can work together) and the bootstrap initialization would be nice.... thanks for the video keep them coming!
@MaZyYTube2 жыл бұрын
@@elvismd Do you not do this via scripts? We load our scenes with scripts. So even if a (init)scene is closed and we hit play button it will get loaded and then the acutally opened map. We work on mmorpg 2d game. Do make even easier you can use one ScriptableObject and add the scenes you definitly need to get loaded if you hit the play button.
@elvismd2 жыл бұрын
@@MaZyYTube Yes we do that, but we usually edit multiple scenes at the same time, including the ones that are systems. So I have everything loaded at once
@elvismd2 жыл бұрын
so no reason to be realoding it everytime I play, I just let it open
@ArtisticallyGinger2 жыл бұрын
I usually use the approach for VR persistance where you load a scene from the toolbar along the top, write a helper script that additively loads the persistant scene in. That way it achieves the same affect :)
@queenofbadjokes9413 Жыл бұрын
the rammstein song at the end made the video even better!
@mehmedcavas3069 Жыл бұрын
i like to use dependency injection for setup code. Having a setup context which is automatically added in every scene helps and you are not depending on singletons. using interfaces instead so can you different type of types of classes with the same interface to create test scenes
@getmads95612 жыл бұрын
Thats a really great tip for handling dependency structure, thank you for the tip!
@navelak2 жыл бұрын
Awesome trick Taro, Im using it from now on! cool hat btw!
@peterroth52872 жыл бұрын
Watching this 3:20 minute video forever released me from being "really cursed" by going to a menu scene every time.
@Tarodev2 жыл бұрын
I'm so glad I could save you from that hell
@fmproductions9132 жыл бұрын
Another good topic! My Unity singletons actually create themselves when they don't exist, which is something as simple as `(new GameObject("Singleton")).AddComponent();` It also gets a DontDestroyOnLoad call. If you need initial state, populated in the inspector, that would require a bit more work to set it up all in code. For Singleton dependencies, it would be possible to abstract them so that scripts use interface types for singletons, and then you can use something like a DI container - basically a class with static methods that lets you register how to resolve requested types. And in the scripts that require the singleton, you can ask this container class to grab the singleton of that type for you. The registration code for how to resolve requested types can be registered in an [InitializeOnLoad] method for example. The following example is a bit different from my own implementation, and I didn't test it, but here is the general idea: The container (SingletonProvider) might have a method like: ``` public static void AddSingleton(Func accessorMethod) { accessorMethodsDictionary[typeof(T)] = accessorMethod; } ``` with the accessorMethodsDictionary being of type Dictionary It registers a getter method that is called when an object wants to access a singleton instance, and in the scripts requiring a singleton, it would be possible to request the accessor method like this: ```SingletonProvider.Get();``` with an implementation that could look like: ``` public static T Get() { if (accessorMethodsDictionary(typeof(T), out object accessor)) { return (accessor as Func).Invoke(); } return default(T); } ```
@ppRadu97 Жыл бұрын
I don't know how your videos get recommended to me just at the right time as I am thinking to myself "how could I reinitialize my persistent singletons on every scene load?". Awesome and concise as always. Thank you!
@MaxIzrin2 жыл бұрын
This is really good, but I would add a Debug.Log in the initialization, to avoid head injury later. Trying to figure out why are these objects spawning in every scene after you forgot you wrote it, can be frustrating. In general I like to avoid this sort of untraceable code, but this looks really convenient, so I'll give it a try.
@JulienNix2 жыл бұрын
I used the "Managers" scene method for a medium-sized project and can confirm it was a pain having to switch to that scene before pressing play. This looks way better
@Madewithmice2 жыл бұрын
I'm just tackling this exact same issue right now. Spooky! Very useful indeed - thank you!
@KolmeGurua2 жыл бұрын
Keep up the GOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOD work!
If you bootstrap your class instances as Singleton, then you can't change the properties before play mode because they are not in your scene yet, but that solves the common problem of linking an object to a Singleton that might be deleted in play mode. Another solution might be to use Scriptable objects, that is if you dont need Start and Update. I think loading a scene because there's Managers in it is more complicated and not the best approach
@arcday42812 жыл бұрын
One of the best "useful" channels! (a little patience and soon there will be 100,000 subscribers or more)
@Tarodev2 жыл бұрын
Thanks arc! I hope so :)
@legendaryswordsman2279 Жыл бұрын
This was an absolute godsent, this is gonna save an insane amount of time in the future, so thanks!
@reyhax71322 жыл бұрын
Never thought of doing it like this. Before I would just make the singleton handle instantiating itself from a static getter if it does not exist. Nice vid!
@rafaelcordoba13 Жыл бұрын
I recommend a lightweight DI framerwork like "VContainer" to handle dependencies and instantiations.
@3enny3oy2 жыл бұрын
Nice and clean. I think I may borrow this. If it’s code anyone else will be looking at, my only hesitation would be calling things systems when ECS has its own very specific meaning for the word.
@Tarodev2 жыл бұрын
That's a valid point. I'll more than likely change it when I begin using ECS. Have you been using it?
@unityecsdev2 жыл бұрын
I often do slightly differently, of course, it can only be used for small projects, I believe for bigger projects an old but gold FSM would be more interesting. So my approach is basically similar but not through prefabs, I have all my managers as interfaces with the dependency inversion principle, basically, they are only accessed via interfaces, and I have a system initialization to initialize each one of them by the order I want. So I have a scene Initializer that holds a system script that starts to kick it off the managers by loading another scene additively called "CommonSystemComponents" here where I hook all my persistent managers.
@DiegoCastares2 жыл бұрын
Nice and clean. Keep up the good work mate!
@EskeltValorant Жыл бұрын
This is really useful! I just subscribed to your channel
@flamingpenny2 жыл бұрын
Have you considered using scriptable objects to store your persistent data? It lets you store them outside the scene so you don't have dependency chains, it lets you build globally accessible lists of runtime objects for stuff like transforms to put on a map, and it decouples their references so you won't have npes when referencing stuff in scene when you switch scenes. You can also include a reset function to reset values between scenes.
@Tarodev2 жыл бұрын
Yup! I use SO architecture in my WIP game. But only to an extent... going full decoupled SO-A makes it feel super fragmented in my opinion.
@niuage2 жыл бұрын
Is that related to the video at all? :D I'd be surprised if he never talked about scriptable objects on this channel, but could be wrong!
@flamingpenny2 жыл бұрын
@@Tarodev That's true, holding each piece of information in it's own object is annoying, especially if you're referencing a bunch of them in one script. It sometimes looks like you have to add a dictionary's worth of references. I just really like how much it separates information so you never get npes from stuff like UI references to things that don't exist in the game world. If I could find a clean workaround for that issue, I'd go back to singletons :)
@flamingpenny2 жыл бұрын
@@niuage Just another solution to getting data in any scene that I found out about. Wondered if he had an opinion on it.
@niuage2 жыл бұрын
@@flamingpenny I see :) For project initialization, I copied how the project built by UInity and the community did it (ChopChop). I'm using SOs as event channel, + SOs representing my scenes. It's going pretty good so far, but a bit more complicated than what he showed here for sure.
@iDigvijaysinhG2 жыл бұрын
3 years in Unity and never thought about this even once _:)
@jeroeno_boy2 жыл бұрын
Thanks! I will definitely use this in my projects!
@LookjaklooK Жыл бұрын
I would just use ScriptableObjects to be honest. So let's say you want an audio manager going, it would be just a scriptable object that handles sound effects/music. And if you want to setup an audio source then you can add it in any scene by just referencing the AudioManager scriptable object to the mono behaviour (a mono behaviour script that sets the scriptable object to work with the audio source). That way, if you let's say don't need audio in any scene, you just don't add it. And this applies to all 'managers', you just add them whenever you actually need them in a scene, as opposed to having to include them in every scene, even in the simplest test scenes.
@stephenkentperez77052 жыл бұрын
Dont stress too much about that quaternion vid, man. But seriously, the hype keeps building up the longer the wait. hahaha🤣
@TriCombStudio2 жыл бұрын
Amazing job. Keep being awesome!
@ajaygamedeveloper61482 жыл бұрын
I used to load main scene and then the scene that I actually want to test, it was really painful process. Thanks for tip
@derkoi2 жыл бұрын
I do something similar but I just instantiate prefabs I need. Using your method, is it possible to prevent adding systems to every scene, maybe just do a simple if scene == check?
@Farmerfromtexas2 жыл бұрын
Simply fantastic. I shall name all my (Systems') children after you!
@gamelsrael2 жыл бұрын
Thanks for this helpful video :D
@jospete55712 жыл бұрын
If you haven't seen it already, I'd recommend watching Ryan Hipple's 2017 talk on game architecture with scriptable objects. He talks about minimizing the use of singletons altogether, which drastically increases testability.
@MattiaBelletti2 жыл бұрын
It is a very good talk; sometimes, though, you cannot use scriptableobjects (like for managing audio)
@jospete55712 жыл бұрын
@@MattiaBelletti can you elaborate on the audio management example? I haven't run into a case so far for singletons that isn't replaceable by a runtime set / delegate pattern combination.
@Tarodev2 жыл бұрын
My absolute favorite talk of all time. But unless you're working with designers, going full SO-A is a bad move in my opinion. Everything becomes so fragmented (for the sake of being fragmented) and hard to follow. It's hard to piece together everything happening as events can be fired from multiple objects. You also need to click multiple objects to get a complete picture (including numbers) instead of just clicking a single object. Don't get me wrong though, I do use his techniques to decouple components which should be decoupled.
@MattiaBelletti2 жыл бұрын
@@jospete5571 oh, you *can* use techniques other than singletons; what I said is that you cannot for example manage audio inside scriptable objects because, well, audio sources must be attached to game objects. But you can have a mixed situation (SO events getting listened to a "system" audio Manager in the scene)
@MaZyYTube2 жыл бұрын
Tarodev, you can do the same but with ScriptableObjects and put your Prefabs into the fields (List) and load them from there. So you don't need to follow the rules to have "Systems". You can put more options into it like naming the gameobject and so on. But the ScriptableObject need to be in the resources folder or at least assigned somewhere as reference. We also added MenuItem so we find the scriptableobject via clicks if we want add more prefabs :D. I have a game with over one million downloads (play store) and this was biiiiiig help to fix little bit my singleton mistakes and also the developement was much easier after this (I had preloading scene and needed to start from there always). I was doing to make this more advanced but had no time for it like just to have Editor Window and add prefabs there and that is. Will be much easier then. To the load scene thing. We are building big mmorpg and we are forced to use preloading scene and for us we think this is the best way. The scene will always be everywhere and only if the scene is finished then the rest gets loaded. With this we even archieved instanced dungeons like we know from World of Warcraft. But needs custom scripts to handle that. For instanced Swapping Scenes gets complicated because one scene need to stay for ever.
@pulpxi2 жыл бұрын
All German r happy because of the music at the end
@lux26402 жыл бұрын
You are a gentleman and a scholar.
@fejza2 жыл бұрын
That shelf in the back needs some more props
@Tarodev2 жыл бұрын
I'll work on that
@TheGreatestChuck2 жыл бұрын
This looks pretty nifty, but I personally prefer the singleton replacement I learnt about recently, namely using ScriptableObjects as your managers.
@DevDunkStudio2 жыл бұрын
No worries about the quaternions lol, no one expects that to be made quickly
@workinglategames74012 жыл бұрын
Nice. I'm going to implement it.
@MarekNijaki2 жыл бұрын
Usefull video. Good work!
@kingofroms72242 жыл бұрын
You are amazing, thanks for intermediate stuff.
@SixBitOfficial2 жыл бұрын
Yer... I'm a sucker for many singletons...this is a great tip!
@ZacIRL2 жыл бұрын
Best gamedev channel. I treat your stuff like gospel during my study. What is your professional history?
@Tarodev2 жыл бұрын
I've been working in cyber security for the last 5 years. Cryptography and trustless architecture. I also maintain enterprise portals I built many years ago. And now... I'm Tarodev :)
@kanarickm2 жыл бұрын
Super super great video!!
@ncatalyst70362 жыл бұрын
Assuming I have 1 player scene that is never unloaded while playing (with mechanisms to ensure this) for any singletons or static classes I have I just wrap their usage with a shim class+interface and then use Zenject for DI.
@evrenbuda2 жыл бұрын
Hi could you please make a video for line renderer mesh baking property? How can we turn our lines to 3d meshes? Especially while dawing line renderer on 3d world?
@pixeldust22342 жыл бұрын
I usually have a scriptable object which holds my system prefabs Then use lazy instantiation to put them in a scene when they are first called
@yurasterniuk2 жыл бұрын
Super super easy, thanks a lot for this tip :D
@JW-uu9je2 жыл бұрын
the timing on this video is great!!! I keep having to go into my initialization screen and its getting annoying!!! tysm
@JW-uu9je2 жыл бұрын
omg and your end credit music...we love you too!!!!
@danielvrsek83702 жыл бұрын
You can replace Singletons with Scriptable Objects. And Reference it in any object you need. Than you doesnt need to care about dependencies.
@joaolira7 Жыл бұрын
Ok, I hope you read this. I would love to see a good vídeo like this one when you create a system manager (like scene transitions, audio manager, etc.) and you can hit play on MAIN MENU scene, or GAME scene, or even GAME OVER scene and it will instantiate the system prefab without any major breakage or null reference while prototyping. It's been a problem to me :/
@tbage22102 жыл бұрын
This is really cool!
@ThiccyDev2 жыл бұрын
Man in hat educates me 😳
@FyresGames2 жыл бұрын
I've tried that. It do load my singletons, but in my awake function one of them got FindObjectsWithTag. But it doesn't work anymore. What should I change to find them?
@GamernetsLP2 жыл бұрын
How would a script now reference these systems though? With a persistent systems class?
@AliRaza-qn9hi2 жыл бұрын
i like you video and its really helpfull, but my question is if we need system prefab is only be loaded on a certain scene,, not to be on every scene then how could i modify the code.
@Paul-zh2jp2 жыл бұрын
This is cool!
@hasanberkcanaydin61952 жыл бұрын
Can someone explain this a bit more? What is the real benefit of this approach and best use of it? On docs, it says this method is after awake method has been invoked and the execution order of methods marked [RuntimeInitializeOnLoadMethod] is not guaranteed. Im a bit confused.
@fleity2 жыл бұрын
Looks much better than having a dedicated scene which needs to be loaded. I strongly dislike it when I can not just press play and actually start the scene I am in. This does not prevent multiple systems prefabs from being instantiated though right? Is before scene load then called for every other additive loaded scene again? If we do this with addressables async isn't it possible that systems will be only available after other classes have looked for it (mostly in Start)?
@Tarodev2 жыл бұрын
In the addressables code I add an await to ensure it's done. This method is called just one time per game load :) Even though the name makes it seem otherwise.
@MarekNijaki2 жыл бұрын
Please pin this comment on top because it could be usefull for Unity begginers
@soverain2 жыл бұрын
Good quality content, as usual! ADIEU
@Tarodev2 жыл бұрын
Adieu!
@nordbros5232 жыл бұрын
Great Tip, Bless 🙏
@lfcamacho2 жыл бұрын
good stuff! ...hey, any update on the timer class thingy video? months ago, when you asked if we had any suggestions for future videos, I suggested a video about the benefits of having a global timer class, and you said you added it to the list... I'm still curious to see how you would implement it :)
@CheeseChuckie2 жыл бұрын
Dude, nice hat. Also the video was cool, too.
@Esbenellocos2 жыл бұрын
Good stuff, Thanks!
@Tymon00002 жыл бұрын
This is the same thing I came up with, I called my game object Singletons instead of Systems though :D
@iamgruff2 жыл бұрын
Bangin 🏆
@modiddymo2 жыл бұрын
Yeah, spicy pattern. Me like.
@gamedevbaiyi9362 жыл бұрын
Hi taro. I noticed you're using Rider too. Could you please make a video about how to debug in rider? There are almost no such tutorials on youtube.