Search Unity

Scene in "Build Settings" or not

Discussion in 'Getting Started' started by romanpinkel, Sep 4, 2019.

  1. romanpinkel

    romanpinkel

    Joined:
    Sep 4, 2019
    Posts:
    20
    hey,
    I'm new to Unity (just saw some tutorials and made beginners stuff) and now I have my important Question:
    If I load a scene which isnt included in the build settings, I can create visible meshs via C#-code.
    If I add those scenes to the Build Settings (which alsways complains if the scene isnt added) and create the visible meshs, they instantly disappear from this scene. (Even no more objects available)
    Also if I create stuff in the Scene from the menu in the scene and the scene isnt in the Build Settings it disapperas on startup.
    Why is that so?
    Is there a way to crossover both sides and when yes, how? Can someone gimme a noob-supporting answer please?
    mfg RP
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    4,519
    Hm, I'm lost in the third sentence.

    Build Settings' scene list determinates which scenes will be added to your final build. If you do not add your scenes there, they won't be part of your game. It is simple like that. It does not have anything to do with the actual content of your scenes.
    If you have problems with your scenes, those have to be addressed. Do you have any concrete errors? Some code? (Using code tags if you submit some)
     
  3. romanpinkel

    romanpinkel

    Joined:
    Sep 4, 2019
    Posts:
    20
    ok, If I create Objects via the Unity enginge itself, they work properly if I include this scene in the Build settings:
    e.g.:
    Ground created UE.jpg

    If I'm using code tho create a Plane it looks like this, but only if I dont include in the Build settings. As soon as I Include it, the code generates this platform and it vanishes upon starting.
    Ground created Code.png

    Code (CSharp):
    1. SceneManager.LoadScene("NeueBaustelle", LoadSceneMode.Single);
    2.  
    3.             // Assigns a material named "Assets/Resources/Mat_Ground" to the object.
    4.             Material planeMat = Resources.Load("Mat_Ground", typeof(Material)) as Material;    
    5.  
    6. //This calls a function which creates a plane with width, length, collider on/off and a material/texture
    7. Create_Terrain_Helper.CreatePlane(X_length,Y_length,true,planeMat);
     
  4. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    4,519
    I believe you're using this wrong. LoadScene does not execute right away. It runs after the end of the current frame.
    https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html
    Which also means you cannot use the new scene in your code right after the LoadScene.

    Move everything you load/generate for the new scene inside the new scene (Awake or Start as needed).
     
  5. romanpinkel

    romanpinkel

    Joined:
    Sep 4, 2019
    Posts:
    20
    thx, now it works as pretended.