Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question online LOAD: racetrack only when needed

Discussion in 'Editor & General Support' started by fla-rar, Jul 14, 2023.

  1. fla-rar

    fla-rar

    Joined:
    May 1, 2014
    Posts:
    248
    hello good morning !
    I am making a game (WEB ONLINE FREE), of racing cars,
    and I would like to know if in Unity3D it is possible that
    the game does not load ALL (200) TRACKS WHEN THE GAME IS STARTED.
    INSTEAD, contrary, just load on the screen,
    the track that will be played,
    even if it takes 3-5 seconds internet loading,
    but ONLY LOAD the track that will be played.
    i will apreciate so much any comment, thanks !
    .
    .
    mautrack picture 001.jpg
     
  2. KillDashNine

    KillDashNine

    Joined:
    Apr 19, 2020
    Posts:
    449
    Are your tracks scenes? What you need is scene loading. Say, your game starts with just the menu screen (scene), and you show the player the track selection, showing previews of your tracks. Then when the player hits "Play", you run
    SceneManager.LoadSceneAsync(selectedscene)
    and start your game. To get even faster, the async loading can be implemented to work in the background so that the scene is mostly loaded when its selected, and then when the player hits "Play" you switch the scene.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Yes, everything that JaakkOS says, plus you can leverage additive scenes to make the individual scenes even easier. For instance, my Jetpack Kurt game has over 100 additive content scenes and a bunch of common partial glue scenes and only one content scene is loaded at a time.

    Screen Shot 2023-07-14 at 5.46.41 PM.png

    My game testbed repo has almost 500 separate scenes, only one or a few loaded at once:

    Screen Shot 2023-07-14 at 5.48.09 PM.png

    Here's how I did it:

    Additive scene loading is one possible solution:

    https://forum.unity.com/threads/right-way-for-performance-divide-scene.1023673/#post-6630961
    https://forum.unity.com/threads/right-way-for-performance-divide-scene.1023673/#post-6754330

    https://forum.unity.com/threads/problem-with-canvas-ui-prefabs.1039075/#post-6726169

    A multi-scene loader thingy:

    https://pastebin.com/Vecczt5Q

    My typical Scene Loader:

    https://gist.github.com/kurtdekker/862da3bc22ee13aff61a7606ece6fdd3

    Other notes on additive scene loading:

    https://forum.unity.com/threads/removing-duplicates-on-load-scene.956568/#post-6233406

    Timing of scene loading:

    https://forum.unity.com/threads/fun...ject-in-the-second-scene.993141/#post-6449718

    Also, if something exists only in one scene, DO NOT MAKE A PREFAB out of it. It's a waste of time and needlessly splits your work between two files, the prefab and the scene, leading to many possible errors and edge cases.

    Two similar examples of checking if everything is ready to go:

    https://forum.unity.com/threads/daily-events-and-content-changes.1108202/#post-7143713

    https://forum.unity.com/threads/uni...on-before-other-scripts.1153739/#post-7401794
     
  4. fla-rar

    fla-rar

    Joined:
    May 1, 2014
    Posts:
    248
    yes, each racetrack is an individual scene, and yes, I was amazed that I didn't know that unity could do this.
    However, I have another question.
    each track scene, you would have to save it separately, externally from the main game, RIGHT ?
    because it will be called separately.
    Is this true ??
    .
    I'm sorry, but this is new to me... Is there any tutorial or documentation to expand on this topic?
    .
    Thank you again very much for the answers.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    YES! This is the magic sauce.

    You should make a little micro project and go do a bit of testing in it... make a scene with a player.

    Make 3 different "content" scenes.

    Have that scene additively load a random content scene (like choose randomly from names).

    Experiment with how you can wait until a spawnpoint appears (such as via a coroutine) so that you can place the player at the right place no matter what level it is.

    When you are done either load another scene (like a "congrats scene"), which unloads all other scenes, or specify the scenes you want to unload. I almost always just go to a fresh new scene to throw out all the old ones at once.
     
  6. fla-rar

    fla-rar

    Joined:
    May 1, 2014
    Posts:
    248
    /
    thanks a lot .... i apreciate this !!!