1 Line Fix for your Unity Project

Sdílet
Vložit
  • čas přidán 24. 10. 2023
  • game.courses/mp/ - Multiplayer Mastery Course
    * for anyone who wants the code, here it is
    using Unity.Services.Core;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    public class Bootstrapper : MonoBehaviour
    {
    async void Start()
    {
    Application.runInBackground = true;
    await UnityServices.InitializeAsync();
    if (SceneManager.loadedSceneCount == 1)
    SceneManager.LoadScene("CarSelection", LoadSceneMode.Additive);
    }
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    static void Init()
    {
    #if UNITY_EDITOR
    var currentlyLoadedEditorScene = SceneManager.GetActiveScene();
    #endif
    if (SceneManager.GetSceneByName("Bootstrapper").isLoaded != true)
    SceneManager.LoadScene("Bootstrapper");
    #if UNITY_EDITOR
    if (currentlyLoadedEditorScene.IsValid())
    SceneManager.LoadSceneAsync(currentlyLoadedEditorScene.name, LoadSceneMode.Additive);
    #else
    SceneManager.LoadSceneAsync("CarSelection", LoadSceneMode.Additive);
    #endif
    }
    }

Komentáře • 48

  • @ComicusFreemanius
    @ComicusFreemanius Před 8 měsíci +70

    A whole video with examples and use cases of this, please.

  • @page0809
    @page0809 Před 8 měsíci +4

    great format, fast, and on the point! Not all topics can be covered this way, but this one is :D

  • @notcseliot
    @notcseliot Před 8 měsíci +9

    It's really useful for error logging as well. Let's say there's something SUPER CRITICALLY wrong with your build and it crashes on load. We can accomplish basic sanity checking by reporting program state as CLOSE TO the program execution as possible.
    So do something like "write 'boot success' to log file" so even if you can't get your program to render, you know AT LEAST that you made it to a point where Unity can fire off that static function.
    Obviously you can extrapolate more data from there when debugging.
    Hope this helps!

  • @Merenstein
    @Merenstein Před 8 měsíci +1

    Already knew this, but I like the fact that the video is short. Thank you for not beating arround the bush !

  • @jean-francoisaquin4344
    @jean-francoisaquin4344 Před 8 měsíci +2

    Extremely useful . Thank you for this tip.

  • @damnpete
    @damnpete Před 8 měsíci +2

    Oh wow. This is awesome... I have been using a Bootstrapper scene for quite a while, but it's always annoying when I don't want to follow the default startup sequence for whatever reason. This little trick of forcefully loading the Bootstrapper in the editor on entering play mode and then resuming to the loaded scene is really neat! Great tip, Jason, thanks!

  • @TolgaDurman
    @TolgaDurman Před 8 měsíci +2

    Perfect! Bootstrapping is a must.

  • @alec_almartson
    @alec_almartson Před 8 měsíci +2

    Thank You for sharing these Quick useful Tips. 💯👍🏻

  • @IndieGearLab
    @IndieGearLab Před 8 měsíci +2

    Simply amazing! Thank you very much!

  • @Neoisrael007
    @Neoisrael007 Před 8 měsíci +3

    i was looking for exectly this for my last steam project and didn't find it, now i know :) Thanks Jason

  • @HadiLePanda
    @HadiLePanda Před 8 měsíci +2

    I really like this style of tips video, it's very helpful thank you 🙏

  • @jacobdunbar1544
    @jacobdunbar1544 Před 8 měsíci +1

    I'll have to give this a go! I've built out some custom editor UIs that essentially do the same thing with some optional parameters (can disable bootstrapping, specify the bootstrap scene, etc) but this seems like a really clean and fast approach, especially for newer projects.

  • @MarcioPuga
    @MarcioPuga Před 4 měsíci

    Thanks so much for this!

  • @LifesMystery777
    @LifesMystery777 Před 8 měsíci +3

    Thanks Jason keep them coming! You know unity and all its assets make it easy to drag and drop an entire game. But I'm slowly learning to code as I go. Almost like backward engineering!

  • @MagicPigGames
    @MagicPigGames Před 8 měsíci +1

    Short and Sweet!

  • @iamgruff
    @iamgruff Před 8 měsíci

    helpful as ever Mr W, good stuff :)

  • @gregridd
    @gregridd Před 8 měsíci +3

    great tip thanks!

  • @castlecodersltd
    @castlecodersltd Před 8 měsíci +2

    Sweet. Thanks ☺

  • @-INC0GNIT0-
    @-INC0GNIT0- Před 8 měsíci +1

    Nice tip !
    Feels somewhat familiar like it's the startup class in a webapplication for businesses

  • @halivudestevez2
    @halivudestevez2 Před 8 měsíci +1

    honestly, no idea what you was trying to show here :D

  • @ChristopherCricketWallace
    @ChristopherCricketWallace Před 8 měsíci

    this is GREAT tip. You don't get this in tutorials. THANK YOU!

  • @gamedevelopmentasahobby
    @gamedevelopmentasahobby Před 8 měsíci +1

    I have a "checkbox" in my Unity Editor UI called "Load First Scene" attached to this script so I can enable/disable it whenever I need, before entering play mode.
    You can see it in my videos showing Unity Editor UI, on top of the screen, next to the play/pause buttons.

    • @twinjuke
      @twinjuke Před 6 měsíci

      how did you put that checkbox there?

  • @cihadturhan
    @cihadturhan Před 8 měsíci

    Thank you! It actually made sense. I used to use a singleton and check if bootstrap is loaded or not. Your method also makes sense.
    But, how about bootstrap has some async operations or coroutines, so I need them to finish?

  • @mikhailhumphries
    @mikhailhumphries Před 8 měsíci +1

    I still understand the purpose of bootstrapping. I understand it can be used for persistent scenes

  • @JMM57
    @JMM57 Před 8 měsíci +3

    I'm pretty new to unity and mostly been using it to make vrchat worlds but I want to create my own game one day and bring it to life so anything is helpful. Thank you for this I keep this in mind when developing.

  • @ribicb
    @ribicb Před 8 měsíci +3

    I found I can set play mode start scene, using same initialize on load scheme:
    UnityEditor.SceneManagement.EditorSceneManager.playModeStartScene = (SceneAsset contining boot scene)
    And then when hitting play that scene gets loaded no matter what scene was opened in editor.

  • @serkillz6426
    @serkillz6426 Před 8 měsíci +1

    I don't know why I constantly start new projects because I keep having this issue I use urp assets and I start a new project that is urp but I still have this issue with the assets being pink it just becomes discouraging that nothing ever works when I try it

  • @DevlexOnline
    @DevlexOnline Před 8 měsíci +1

    For what do you build in the Start() Method?

  • @ProfessionalJason
    @ProfessionalJason Před 8 měsíci +1

    You make a Bootstrapper Monobehavior which loads other scenes additively. And where does the GameObject that has this Monobehavior live? Is it required to exist in every other scene? From what I see in the documentation, it looks like that attribute will call a static function on any class, so you wouldn't need to have a BootStrapper GameObject at all. Is this correct?

    • @Unity3dCollege
      @Unity3dCollege  Před 8 měsíci

      Correct. The Game object and scene part is totally optional

  • @tabuuforte8546
    @tabuuforte8546 Před 8 měsíci +1

    I've been developing a fan made Smash Bros. for years, and am embarrassed to say, I don't know wtf a boostrap is.

  • @ethanwasme4307
    @ethanwasme4307 Před 8 měsíci +1

    I wish you could clone yourself and start an unreal channel :P still, in a way i learn more trying to conceptualise it in unreal terms

  • @blinkachu5275
    @blinkachu5275 Před 8 měsíci +11

    Okay so while it's cool that you show the code and such.... WHY should someone use this? Like what's the use case? What benefit does it give to the project?

    • @PixelDough
      @PixelDough Před 8 měsíci +1

      One idea is because a lot of time you want certain objects to be persistent across the entire game. You can put it as a prefab in every scene and move it to DontDestroyOnLoad, but then you have to manage what happens when scenes load containing that object. This way, you can have certain code run when the game runs, regardless of what scenes are in your game, or how they're configured. This way you can guarantee your editor play mode starts the same way your built game does

    • @Deatheragenator
      @Deatheragenator Před 8 měsíci

      I also want to know the point.

    • @Efim141
      @Efim141 Před 8 měsíci

      If you have fast startup enabled in the editor settings you have to use this method to call a method that will reset/cleanup any static variables in your class, otherwise you’ll see weird errors while running the game

    • @ComicusFreemanius
      @ComicusFreemanius Před 8 měsíci

      ​@@PixelDough I've been using one scene and pooling and just replacing everything in the scene 🤣

    • @KyryloVesna
      @KyryloVesna Před 8 měsíci

      Also you can init your services in right order, I guess

  • @Daeniak57
    @Daeniak57 Před 8 měsíci

    I like cookies

  • @SMGtk
    @SMGtk Před 8 měsíci

    Didn't understand

  • @denisgoodman4492
    @denisgoodman4492 Před 8 měsíci +1

    Is Good, But (IMHO):
    SceneManager.loadedSceneCount = SceneManager.sceneCount ?
    and
    Must be Noted that It demanding to install Service.Core package and include Unity.Service.Core in corresponding asmdef

  • @TYNEPUNK
    @TYNEPUNK Před 8 měsíci

    cant see any value in this.

  • @vizionthing
    @vizionthing Před 8 měsíci

    My line that fixed unity was rmdir

  • @Seeks__
    @Seeks__ Před 8 měsíci

    Unity is as trash as the company behind it.

  • @m_maksym
    @m_maksym Před 8 měsíci

    why VS underlines red "using Unity.Services.Core; " and " await UnityServices.InitializeAsync(); "