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. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Problems adding scenes into lists or arrays

Discussion in 'Scripting' started by Nostradamuzzz, Sep 25, 2022.

  1. Nostradamuzzz

    Nostradamuzzz

    Joined:
    Jan 19, 2022
    Posts:
    9
    Hi everyone.

    Ive been trying to create a game where the player has a list of scenes to go through before ending a run and later starting a new one.
    Imagine them as Scene1, Scene2, etc. Which are all part of the build.

    The problem I've been having is how to:

    1. Create Lists with specific scenes (example: DesertScenesList) that Ive previously selected (all desert scenes (Desert1Scene, Desert2Scene, etc )...as an example) to organize gameplay.

    2. Add Scenes to a new list (NewRunList), during RunTime, that pulls from the Scenemanager using its methods and adds a specific (or radom) scene to it from those previosuly created lists (DesertScenesList).

    3. Loading a scene from the new list (NewRunList)

    Any Idea how to do something like this? I understand the Load methods I have to use later but Ive been going back and forth with this for weeks and havent had any breakthoughs.

    I'd appreciate any insights you may give me

    Thank you
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    6,821
    I'm not really sure what you are trying to accomplish, but scenes can be loaded by their name, so you could just have a string list that holds the names of the scenes.
     
  3. Nostradamuzzz

    Nostradamuzzz

    Joined:
    Jan 19, 2022
    Posts:
    9
    Thank you for the quick reply. Could you provide an example on how to implement it?

    What I am trying to accomplish is a game where the player has to go through a list of very short levels (for example) and the way the player solves those levels adds other levels of that same type to the list.

    For example:
    • A List of 10 levels to accomplish in one run (a game loop that the player will repeat). The NewRunList includes (DesertLevel 1, WaterLevel1, GrassLevel1, etc..)
    • The player starts the run (of 10 levels) and one is drawn randomly from NewRunList. The player completes that level and then passes to the next one that is also randomly selected from the levels that have not yet been completed of the NewRunList.
    • Everytime a player completes a level (DesertLevel1 for example) based on how many coins (for example) he has collected a new level is added to the NewRunList (DesertLevel2 for example) from a previously created list that includes all of the DesertTypeLevels.
    Strings might be an approach but Im still unsure how to implement it.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    29,558
    Which part of:

    - string collections
    - choosing randomly from a collection
    - scene loading

    Are you struggling with?? There are literally thousands of tutorials and examples out there for all of these things.

    EDIT: is this still the same question from here?! https://forum.unity.com/threads/random-scene.1312053/#post-8300379

    Just put your game gently aside and get familiar with collections... that's less than an afternoon of learning, not months and months.

    Additive scene loading is another 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
     
  5. Nostradamuzzz

    Nostradamuzzz

    Joined:
    Jan 19, 2022
    Posts:
    9
    Dekker.
    I have changed how I approached the problem that I posted in the other thread, that is why I decided to open a new one.
    I am also learning as I go and thought it best to ask here.
    I will check the links you have provided.
     
unityunity